Question printdocument.printersettings.defaultpagesettings vs printdocument.defaultpagesettings

Post number 9 has been selected as best answer.

Joined
Jan 23, 2011
Messages
20
Programming Experience
10+
What is the difference between:
printdocument.printersettings.defaultpagesettings and printdocument.defaultpagesettings

and when should each be used?

Been searching what seems to me to be an obvious question, but it seems that no one else is confused enough to ask.

When I use Quickwatch to look at them they appear to have identical properties.
 
Joined
Jan 23, 2011
Messages
20
Programming Experience
10+
They are the same until you assign a new PageSettings object to DefaultPageSettings Property.
I must be missing something simple. Both DefaultPageSettings properties can be set with a PageSettings object..

When is it appropriate to use each.

Thanks
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,251
Location
Sydney, Australia
Programming Experience
10+
Both DefaultPageSettings properties can be set with a PageSettings object.
Both properties are that type but they can't both be set because PrinterSettings.DefaultPageSettings is read-only.
 
Joined
Jan 23, 2011
Messages
20
Programming Experience
10+
PrintDocument.DefaultPageSettings Property
Gets or sets page settings that are used as defaults for all pages to be printed.
[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PageSettings DefaultPageSettings { get; set; }

I still haven't figured out when to use the above and when to use the below. Which one should I set?

PrinterSettings.DefaultPageSettings Property
Gets the default page settings for this printer.
public System.Drawing.Printing.PageSettings DefaultPageSettings { get; }
I just noticed the PrinterSettings.DefaultPageSettings does not have a {set;} But I've been testing (in ignorance) and have seem to have violated what the doc says. I ran the code below.

Dim pR As Printing.PrinterResolution = New Printing.PrinterResolution With {
.X = 100 + pD.DefaultPageSettings.PrinterResolution.X,
.Y = 100 + pD.DefaultPageSettings.PrinterResolution.Y
}
pD.PrinterSettings.DefaultPageSettings.PrinterResolution = pR

Below from QuickWatch (It showed 600,600 before the above code was run)
pD.PrinterSettings.DefaultPageSettings.PrinterResolution {[PrinterResolution X=700 Y=700]} System.Drawing.Printing.PrinterResolution

Comments please!
 
Last edited:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,377
Location
Norway
Programming Experience
10+
Setting means pD.DefaultPageSettings = new PageSettings()
When you do pD.DefaultPageSettings.PrinterResolution you are getting DefaultPageSettings.
 
Joined
Jan 23, 2011
Messages
20
Programming Experience
10+
Setting means pD.DefaultPageSettings = new PageSettings()
When you do pD.DefaultPageSettings.PrinterResolution you are getting DefaultPageSettings.
So I can change the properties that are not readonly, but can not replace the object reference.
Still, if I want to change the size do I use printdocument.printersettings.defaultpagesettings or printdocument.defaultpagesettings

thanks
 
Top Bottom