ShowPageSetup Method, pgBottom, pgLeft, pgRight, pgTop, pgMinBottom, pgMinLeft, pgMinRight, pgMinTop, pgScale

Purpose

Creates a Page Setup dialog box that enables the user to specify the attributes of a printed page. These attributes include the paper size and source, the page orientation (portrait or landscape), and the width of the page margins.

Syntax

CommDlg.ShowPageSetup

CommDlg.pgBottom [ = long ]
CommDlg.pgLeft [ = long ]
CommDlg.pgRight [ = long ]
CommDlg.pgTop [ = long ]
CommDlg.pgMinBottom [ = long ]
CommDlg.pgMinLeft [ = long ]
CommDlg.pgMinRight [ = long ]
CommDlg.pgMinTop [ = long ]
CommDlg.pgScale [ = long ]

CommDlg.DevNames [ = string ]

Description

The ShowPageSetup method enables to set printer page attributes, including the paper size and source, the page orientation (portrait or landscape), and the width of the page margins.

The pgBottom, pgLeft, pgRight, and pgTop properties return or set the widths of the left, top, right, and bottom margins for your document. The Flags property must include the cdpsMargins. The margin units are determined by pgScale. pgScale = 1 indicates that hundredths of millimeters (1/100 mm) are the unit of measurement for margins and paper size. When pgScale = 2 thousandths of inches (1/1000 inch) is the measurement unit. Setting the property implicitly modifies Flags with either $4 or $8.

The pgMinBottom, pgMinLeft, pgMinRight, and pgMinTop properties set the minimum allowable values for the left, top, right, and bottom margin input boxes of the dialog box. Input below these values is reset to the minimum settings specified. The Flags property must include the cdpsMinMargins.

The DevNames property returns the selected printer as a string with, comma delimited, Driver, Device, and Output Port. For example "WINSPOOL,HP Laserjet 4,LPT1:".

The Flags property values for ShowPageSetup are:

Flags Meaning
cdpsMinMargins $1 The pgMinBottom, pgMinLeft, pgMinRight, and pgMinTop properties are used to initialize the dialog box.
cdpsMargins $2 The pgBottom, pgLeft, pgRight, and pgTop properties are used to initialize the dialog box.
$4 Hundredths of millimeters are the unit of measurement for margins and paper size (set by pgScale = 1).
$8 Thousandths of inches are the unit of measurement for margins and paper size (set by pgScale = 2).
cdpsDisableMargins $10 Disables the margin controls, preventing the user from setting the margins.
cdpsDisablePrinter $20 Disables the Printer button, preventing the user from invoking a dialog box that contains additional printer setup information.
cdpsNoWarning $80 Prevents the system from displaying a warning message when there is no default printer.
cdpsDisableOrientation $100 Disables the orientation controls, preventing the user from setting the page orientation.
cdpsReturnDefault $400 Returns the standard printer in DevNames without showing the dialog box.
cdpsDisablePaper $200 Disables the paper controls, preventing the user from setting page parameters such as the paper size and source.
cdpsShowHelp $800 Displays the Help button
cdpsDisablePagePainting $80000 Prevents the dialog box from drawing the contents of the sample page.
cdpsNoNetworkButton $2000000 Hides and disables the Network button.

Example

Ocx CommDlg cd

cd.Flags = cdpsMargins | cdpsMinMargins

cd.pgScale = 1          ' 1/100 mm

cd.pgBottom = 1000      ' 10 mm

cd.pgLeft = 1000        ' 10 mm

cd.pgRight = 1000       ' 10 mm

cd.pgTop = 1000         ' 10 mm

cd.pgMinBottom = cd.pgBottom

cd.pgMinLeft = cd.pgLeft

cd.pgMinRight = cd.pgRight

cd.pgMinTop = cd.pgTop

cd.ShowPageSetup

Debug.Show

Trace cd.pgBottom    ' use for the documents

Trace cd.pgLeft

Trace cd.pgRight

Trace cd.pgTop

Trace cd.DevNames    ' The selected device

Set Printer = cd     ' Assign to Printer object

' Show the new Printer settings for the device …

Trace Printer.DefLeft

Trace Printer.Width

Trace Printer.DeviceName

Trace Printer.Orientation

Trace Printer.dmPaperSize

Me.Close

Remarks

The return values in pgBottom, pgLeft, pgRight, and pgTop return margin settings for your documents. They have no relation whatsoever with the capabilities of the printer. Other settings made with ShowPageSetup common dialog box are available only when you make the selection the default for the application. This accomplished by setting the CommDlg object as the new Printer object. The Printer object is then initialized using the DEVMODE structure which is a shared object between the Print and PageSetup dialog box. The DEVMODE fields set with the ShowPageSetup dialog box are then available through the Printer's (device mode dm) properties.

When the ShowPrint dialog box is displayed it uses the shared DEVMODE structure, which might have been changed through the use of the Printer properties, to fill in the controls of the dialog box. Changing printing attributes in the ShowPrint dialog box doesn't make the effective until you re-assign the CommDlg object to the Printer object.

See Also

CommDlg, ShowPrint, Dlg Print, dm-Properties

{Created by Sjouke Hamstra; Last updated: 23/10/2014 by James Gaite}