PrinterSetup

From Xojo Documentation

Class (inherits from Object)

Used to get and set the page setup settings.

Properties
Height fa-lock-32.png MaxVerticalResolution SetupString
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
MaxHorizontalResolution PageWidth fa-lock-32.png
Methods
PageSetupDialog

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 MaxHorizontalResolution and MaxVerticalResolution 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 OpenPrinterDialog 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%.

MaxHorizontalResolution and MaxVerticalResolution

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:

Dim settings As String
Dim pageSetup As PrinterSetup
pageSetup = New PrinterSetup
If pageSetup.PageSetupDialog Then
settings = pageSetup.SetupString
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:

Dim pageSetup As PrinterSetup
pageSetup = New PrinterSetup
pageSetup.SetupString = settings
If pageSetup.PageSetupDialog Then
settings = pageSetup.SetupString
End If

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

Dim g As Graphics
Dim p As PrinterSetup
p = New PrinterSetup
If p.PageSetupDialog Then
g = OpenPrinterDialog(p)
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.

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

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

See Also

Graphics, StyledTextPrinter classes; OpenPrinter, OpenPrinterDialog functions.