PrinterSetup

From Xojo Documentation

Revision as of 18:56, 19 November 2009 by WikiSysop (talk) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Description

Used to get and set the page setup settings.


Super Class

Object

Properties

Name Type Description
Height
Integer The height of the printable area on the page (in pixels).

The height is the PageHeight minus the margins.

HorizontalResolution
Integer The horizontal resolution in dots per inch of the output device (usually a printer).
Landscape
Introduced 2007r4
Boolean Gets and sets the landscape state of the PrinterSetup object.

It is True for the landscape orientation; False otherwise. Currently supported on Windows and Mac OS X only.

Left Integer The left origin of the printable area.

This should always be zero.

MaxHorizontalResolution Integer Set to the maximum horizontal resolution at which you wish to print. The default value is 72.

You can change it to the maximum printer resolution you're prepared to handle or -1 for the highest possible resolution of the output device. After calling PageSetupDialog, OpenPrinter, or OpenPrinterDialog, the HorizontalResolution property will automatically be set to the highest resolution supported by the printer driver, within your specified constraints. Printing will then occur at that resolution. This will not affect existing code.

MaxVerticalResolution Integer Set to the maximum vertical resolution at which you wish to print. The default value is 72.

You can change it to the maximum printer resolution you're prepared to handle or -1 for the highest possible resolution of the output device. After calling PageSetupDialog, OpenPrinter, or OpenPrinterDialog, the VerticalResolution property will automatically be set to the highest resolution supported by the printer driver, within your specified constraints. Printing will then occur at that resolution. This will not affect existing code.

PageHeight
Integer The height of the page in pixels.
PageLeft
Integer The offset distance (in pixels) from the left margin of the printable area to the left edge of the physical page, i.e., the left margin.
PageTop
Integer The offset distance (in pixels) from the top margin of the printable area to the top edge of the physical page, i.e., the top margin.
PageWidth
Integer The width of the page in pixels.
SetupString String A value that represents all of the other properties.

When the user clicks OK in the Page Setup dialog box, this value will be populated. You can then store this value to store the user's Page Setup settings. Assigning one of these stored values to this property will then update all of the other properties restoring the page setup settings.

Top
Integer The top origin of the printable area. This should always be zero.
VerticalResolution
Integer The vertical resolution in dots per inch of the output device (usually a printer).
Width
Integer The width of the printable area on the page in pixels. The width is the PageWidth minus the margins.


Methods

Name Parameters Return Type Description
PageSetupDialog [window as Window] Boolean Displays the standard Page Setup dialog box.

If the SetupString property has been populated before this method is called, the Page Setup dialog box will reflect the settings stored in the SetupString property. After the user clicks the OK button to close the Page Setup dialog box, all of the PrinterSetup properties will be updated to reflect the settings the user chose. PageSetupDialog takes an optional parameter, window. If passed, window is a dialog or sheet window that you wish to use as the Page Setup dialog box instead of the built in dialog. Returns a Boolean. This function returns True if the User clicks OK and False if the user clicks Cancel.


Notes

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%.

The Page Setup dialog is not supported on Linux builds. Calling this function will return False with no dialog presented to the user.


MaxHorizontalResolution and MaxVerticalResolution

These properties enable you to print at higher resolutions than 72 dpi. In general, you will need to scale the material being printed (and perhaps the size of the controls) to get the desired results. For example, if you are printing styled text in a TextArea using DrawBlock, you will need to make commensurate changes to the font size(s) to get WYSIWYG output. Doubling the resolution will require that you double the font size; otherwise you will get text that is half the size of the screen font.


Examples

This example 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 example restores the page setup settings stored in a 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 example 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 p as PrinterSetup
p=New PrinterSetup
If p.PageSetupDialog then
If g<> Nil then
  g.DrawString "Hello World", 50,50
 End if
End if

This example displays the Page Setup box and then displays the page size, printable area, and margins in StaticText 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
staticText1.text="PageLeft="+Str(p.pageLeft)
staticText2.text="PageTop="+Str(p.pagetop)
staticText3.text="PageHeight="+Str(p.pageheight)
staticText4.text="PageWidth="+Str(p.pagewidth)
staticText5.text="Height="+Str(p.Height)
staticText6.text="Width="+Str(p.width)
staticText7.text="Computed height="+Str(p.height-2*p.pagetop)
staticText8.text="Computed width="+Str(p.width-2*p.pageleft)


See Also

Graphics, StyledTextPrinter classes; OpenPrinter, OpenPrinterDialog functions.