PrinterSetup

From Xojo Documentation

Class (inherits from Object)

Used to get and set the page setup settings.

Properties
Height fa-lock-32.png MaximumVerticalResolution Settings
HorizontalResolution fa-lock-32.png PageHeight fa-lock-32.png Top fa-lock-32.png
Landscape PageLeft fa-lock-32.png VerticalResolution fa-lock-32.png
Left fa-lock-32.png PageTop fa-lock-32.png Width fa-lock-32.png
MaximumHorizontalResolution PageWidth fa-lock-32.png
Methods
ShowPageSetupDialog ShowPrinterDialog
Shared Methods
OpenPrinter

Notes

The printer reports back a virtual drawing surface that has the resolution supplied in the HorizontalResolution and VerticalResolution properties. This varies by OS platform. Actual printing resolution is determined by the printer based on guidance provided by you using the MaximumHorizontalResolution and MaximumVerticalResolution properties.

When drawing to the Graphic object returned by OpenPrinter, you should always use the HorizontalResolution and VerticalResolution properties to ensure correct sizing. This allows your print output to draw correctly when the printer draws at its native resolution.

Passing a PrinterSetup object to the OpenPrinter or ShowPrinterDialog functions will cause the printer to utilize those PrinterSetup object's properties when printing. For example, if the user chose 200% for the scale in the Page Setup dialog box, the printer would automatically print at 200%.

MaximumHorizontalResolution and MaximumVerticalResolution

These tell the printer the maximum resolutions you would like to use. Changing these does not mean the printer will use the resolutions you specify. You still have to use the HorizontalResolution and VerticalResolution properties to get the resolution to use for drawing.

Sample Code

This code displays the Page Setup dialog box and then stores the settings the user chose in a variable:

Var s As String
Var pageSetup As PrinterSetup
pageSetup = New PrinterSetup
If pageSetup.ShowPageSetupDialog Then
s = pageSetup.Settings
End If

This code restores the page setup settings stored in a String variable called "settings" and then displays the Page Setup dialog box with those settings:

Var pageSetup As PrinterSetup
pageSetup = New PrinterSetup
pageSetup.Settings = s
If pageSetup.ShowPageSetupDialog Then
s = pageSetup.Settings
End If

This code displays the Page Setup dialog box and then passes the settings the user chose to the PrinterSetup.ShowPrinterDialog function. It then prints a sample string:

Var g As Graphics
Var p As PrinterSetup
p = New PrinterSetup
If p.ShowPageSetupDialog Then
g = p.ShowPrinterDialog
If g <> Nil Then
g.DrawString("Hello World", 50, 50)
End If
End If

This code displays the Page Setup box and then displays the page size, printable area, and margins in Label controls. Results, of course, depend on the page size that the user selects. Since PageLeft and PageTop are the horizontal and vertical margins as measured from the printable area rather than the edge of the page, they are negative.

Var settings As String
Var p As PrinterSetup
p = New PrinterSetup
If p.PageSetupDialog Then
settings = p.SetupString
End If

Label1.Value = "PageLeft=" + p.PageLeft.ToString
Label2.Value = "PageTop=" + p.PageTop.ToString
Label3.Value = "PageHeight=" + p.PageHeight.ToString
Label4.Value = "PageWidth=" + p.PageWidth.ToString
Label5.Value = "Height=" + p.Height.ToString
Label6.Value = "Width=" + p.Width.ToString
Label7.Value = "Computed height=" + Str(p.Height - 2 * p.PageTop)
Label8.Value = "Computed width=" + Str(p.Width - 2 * p.PageLeft)

See Also

Graphics, StyledTextPrinter classes; OpenPrinter, ShowPrinterDialog functions.