Display Window's Page Setup Dialog from VB.NET
From .NET you can display Windows standard Page Setup Dialog using the
PageSetupDialog object. While this object derives from the System.Windows.Forms
namespace you need to create a PrintDocument which
derives from the System.Drawing.Printing namespace.
Private myDocumentToPrint As PrintDocument
Private myPageAlreadySetUp As Boolean = False
The PrintDocument object is the key to printing in .NET. and is similar to VB6's
Printer object. Click here to learn
more about using the PrintDocument object.
The PageSetupDialog object lets you display the Page Setup Dialog and control
which features, such as paper orientation, printer selection, etc., are
available by setting the corresponding properties. However, these settings are
only in effect for the PrintDocument you associate with your PageSetupDialog
Dim psd As New PageSetupDialog
.AllowMargins = True
.AllowOrientation = True
.AllowPaper = True
.AllowPrinter = True
.ShowHelp = True
.ShowNetwork = True
.Document = myDocumentToPrint
After instantiating a PageSetupDialog object you can set its default values
prior to showing the dialog. Typically you would do this before showing the
dialog the first time. Subsequently you would just let the dialog display the
' Set defaults on initial display.
If Not myPageAlreadySetUp Then
.Margins.Top = 50
.Margins.Left = 50
.Margins.Right = 50
.Margins.Bottom = 50
.Landscape = True
' Show the Page Setup Dialog.