The PrinterSettings Class Printing

179 An enumeration of type PaperSourceKind expressing the paper source in terms of standard names, such as Lower and Upper . SourceName A string giving the name of the paper source, such as Lower and Upper . PrinterResolution Indicates the resolution capability of the printer. The syntax of the PrinterResolution property is: Public Property PrinterResolution As _ System.Drawing.Printing.PrinterResolution The PrinterResolution class has three properties: X An Integer expressing the horizontal resolution of the printer in dots per inch. Y An Integer expressing the vertical resolution of the printer in dots per inch. Kind An enumeration of type PrinterResolutionKind expressing the resolution mode. The values of this enumeration are Draft , Low , Medium , High , and Custom . PrinterSettings Indicates the settings applicable to the printer being used. The syntax of the PrinterSettings property is: Public Property PrinterSettings As _ System.Drawing.Printing.PrinterSettings The PrinterSettings class is described in the next section.

4.7.6 The PrinterSettings Class

The PrinterSettings class holds values that describe the capabilities and settings of a specific printer. It exposes these properties: CanDuplex Indicates whether the printer can print on both sides of the paper. The syntax of the CanDuplex property is: Public ReadOnly Property CanDuplex As Boolean Collate Indicates whether the document being printed will be collated. The syntax of the Collate property is: 180 Public Property Collate As Boolean Copies Indicates the number of copies to print. The syntax of the Copies property is: Public Property Copies As Short DefaultPageSettings Indicates the default page settings for this printer. The syntax of the DefaultPageSettings property is: Public ReadOnly Property DefaultPageSettings As _ System.Drawing.Printing.PageSettings The PageSettings class was described in the previous section. Duplex Indicates whether the print job is to print on both sides of the paper. The syntax of the Duplex property is: Public Property Duplex As System.Drawing.Printing.Duplex The Duplex type is an enumeration with the following values: Simplex The document will print only on one side of each page. Horizontal The document will print using both sides of each page. Vertical The document will print using both sides of each page, and the second side will be inverted to work with vertical binding. Default The document will print using the printers default duplex mode. FromPage Specifies the first page to print if the PrintRange property is set to SomePages . The syntax of the FromPage property is: Public Property FromPage As Integer InstalledPrinters Indicates the names of the printers installed on the computer. This list includes only the printers physically connected to the machine if any, not necessarily all printers set up in the Control Panel. The syntax of the InstalledPrinters property is: Public Shared ReadOnly Property InstalledPrinters As _ 181 System.Drawing.Printing.PrinterSettings.StringCollection The StringCollection class is a collection of strings. It can be iterated using code such as this: Assume pts is of type PrinterSettings. Dim str As String For Each str In pts.InstalledPrinters Console.WriteLinestr Next IsDefaultPrinter Indicates whether this printer is the users default printer. The syntax of the IsDefaultPrinter property is: Public ReadOnly Property IsDefaultPrinter As Boolean If the PrinterName property is explicitly set to anything other than Nothing , this property always returns False . IsPlotter Indicates whether this printer is a plotter. The syntax of the IsPlotter property is: Public ReadOnly Property IsPlotter As Boolean IsValid Indicates whether the PrinterName property designates a valid printer. The syntax of the IsValid property is: Public ReadOnly Property IsValid As Boolean This property is useful if the PrinterName property is being set explicitly. If the PrinterName is set as a result of allowing the user to select a printer through the PrintDialog dialog box, this property will always be True . LandscapeAngle Indicates the angle in degrees by which portrait orientation is rotated to produce landscape orientation. The syntax of the LandscapeAngle property is: Public ReadOnly Property LandscapeAngle As Integer This value can only be 90 or 270. If landscape orientation is not supported, this value can only be 0. MaximumCopies Indicates the maximum number of copies that the printer can print at one time. The syntax of the MaximumCopies property is: Public ReadOnly Property MaximumCopies As Integer MaximumPage Indicates the highest page number that can be entered in a PrintDialog dialog box. The syntax of the MaximumPage property is: 182 Public Property MaximumPage As Integer Set this value prior to calling the PrintDialog objects ShowDialog method to prohibit the user from entering a page number that is too high. MinimumPage Indicates the lowest page number that can be entered in a PrintDialog dialog box. The syntax of the MinimumPage property is: Public Property MinimumPage As Integer Set this value prior to calling the PrintDialog objects ShowDialog method to prohibit the user from entering a page number that is too low. PaperSizes Indicates the paper sizes that are supported by this printer. The syntax of the PaperSizes property is: Public ReadOnly Property PaperSizes As _ System.Drawing.Printing.PrinterSettings+PaperSizeCollection The PaperSizeCollection is a collection of objects of type PaperSize. The PaperSize type was described in the previous section, under the description for the PaperSize property of the PageSettings class. The PaperSizeCollection can be iterated using the following code: Assume pts is of type PrinterSettings. Dim pprSize As PaperSize For Each pprSize In pts.PaperSizes Console.WriteLinepprSize.PaperName Next PaperSources Indicates the paper sources that are available on the printer. The syntax of the PaperSources property is: Public ReadOnly Property PaperSources As _ System.Drawing.Printing.PrinterSettings+PaperSourceCollection The PaperSourceCollection is a collection of objects of type PaperSource. The PaperSource type was described in the previous section, under the description for the PaperSource property of the PageSettings class. The PaperSourceCollection can be iterated using the following code: Assume pts is of type PrinterSettings. Dim pprSource As PaperSource For Each pprSource In pts.PaperSources Console.WriteLinepprSource.SourceName Next PrinterName Indicates the name of the printer. The syntax of the PrinterName property is: Public Property PrinterName As String Unless a string has been explicitly assigned to the property, its value is Null . 183 PrinterResolutions Indicates the resolution supported by this printer. The syntax of the PrinterResolutions property is: Public ReadOnly Property PrinterResolutions As _ System.Drawing.Printing.PrinterSettings.PrinterResolutionCollection The PrinterResolutionCollection is a collection of objects of type PrinterResolution. The PrinterResolution type was described in the previous section, under the description for the PrinterResolution property of the PageSettings class. The PrinterResolutionCollection can be iterated using the following code: Assume pts is of type PrinterSettings. Dim ptrResolution As PrinterResolution For Each ptrResolution In pts.PrinterResolutions Console.WriteLineptrResolution.Kind.ToString Next PrintRange Indicates the range of pages that are to be printed. The syntax of the PrintRange property is: Public Property PrintRange As System.Drawing.Printing.PrintRange The PrintRange type is an enumeration having the following values: AllPages Prints the entire document. Selection Prints only the selected portion of the document. SomePages Prints the pages starting at the page specified in the FromPage property and ending at the page specified in the ToPage property. SupportsColor Indicates whether the printer supports color printing. The syntax of the SupportsColor property is: Public ReadOnly Property SupportsColor As Boolean ToPage Specifies the final page to print if the PrintRange property is set to SomePages . The syntax of the ToPage property is: Public Property ToPage As Integer The methods of the PrinterSettings class are: Clone 184 Creates a copy of the PrinterSettings object. The syntax of the Clone method is: Public NotOverridable Function Clone As Object _ Implements System.ICloneable.Clone GetHdevmode Returns a handle to a Windows DEVMODE device mode structure corresponding to this PrinterSettings object. The GetHdevmode method has two forms: Public Overloads Function GetHdevmode As System.IntPtr and: Public Overloads Function GetHdevmode _ ByVal pageSettings As System.Drawing.Printing.PageSettings _ As System.IntPtr The DEVMODE structure is part of the Windows API and is not discussed further in this book. GetHdevnames Returns a handle to a Windows DEVNAMES structure corresponding to this PrinterSettings object. The syntax of the GetHdevnames method is: Public Function GetHdevnames As System.IntPtr The DEVNAMES structure is part of the Windows API and is not discussed further in this book. SetHdevmode Sets properties of this PrinterSettings object based on values in the given DEVMODE structure. The syntax of the SetHdevmode method is: Public Sub SetHdevmodeByVal hdevmode As System.IntPtr The DEVMODE structure is part of the Windows API and is not discussed further in this book. SetHdevnames Sets properties of this PrinterSettings object based on values in the given DEVNAMES structure. The syntax of the SetHdevnames method is: Public Sub SetHdevnamesByVal hdevnames As System.IntPtr The DEVNAMES structure is part of the Windows API and is not discussed further in this book.

4.7.7 Page Setup Dialog Box