PageSetupDialog Class

Enables users to change page-related print settings, including margins and paper orientation. This class cannot be inherited.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public NotInheritable Class PageSetupDialog _
	Inherits CommonDialog

The PageSetupDialog type exposes the following members.

  NameDescription
Public methodPageSetupDialogInitializes a new instance of the PageSetupDialog class.
Top

  NameDescription
Public propertyAllowMarginsGets or sets a value indicating whether the margins section of the dialog box is enabled.
Public propertyAllowOrientationGets or sets a value indicating whether the orientation section of the dialog box (landscape versus portrait) is enabled.
Public propertyAllowPaperGets or sets a value indicating whether the paper section of the dialog box (paper size and paper source) is enabled.
Public propertyAllowPrinterGets or sets a value indicating whether the Printer button is enabled.
Public propertyContainerGets the IContainer that contains the Component. (Inherited from Component.)
Public propertyDocumentGets or sets a value indicating the PrintDocument to get page settings from.
Public propertyEnableMetricGets or sets a value indicating whether the margin settings, when displayed in millimeters, should be automatically converted to and from hundredths of an inch.
Public propertyMinMarginsGets or sets a value indicating the minimum margins, in hundredths of an inch, the user is allowed to select.
Public propertyPageSettingsGets or sets a value indicating the page settings to modify.
Public propertyPrinterSettingsGets or sets the printer settings that are modified when the user clicks the Printer button in the dialog.
Public propertyShowHelpGets or sets a value indicating whether the Help button is visible.
Public propertyShowNetworkGets or sets a value indicating whether the Network button is visible.
Public propertySiteGets or sets the ISite of the Component. (Inherited from Component.)
Public propertyTagGets or sets an object that contains data about the control. (Inherited from CommonDialog.)
Top

  NameDescription
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDisposeReleases all resources used by the Component. (Inherited from Component.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodResetResets all options to their default values. (Overrides CommonDialog.Reset.)
Public methodShowDialogRuns a common dialog box with a default owner. (Inherited from CommonDialog.)
Public methodShowDialog(IWin32Window)Runs a common dialog box with the specified owner. (Inherited from CommonDialog.)
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)
Top

  NameDescription
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
Public eventHelpRequestOccurs when the user clicks the Help button on a common dialog box. (Inherited from CommonDialog.)
Top

The PageSetupDialog dialog box modifies the PageSettings and PrinterSettings information for a given Document. The user can enable sections of the dialog box to manipulate printing and margins; paper orientation, size, and source; and to show Help and network buttons. The MinMargins property defines the minimum margins a user can select.

When you create an instance of the PageSetupDialog class, the read/write properties are set to initial values. For a list of these values, see the PageSetupDialog constructor.

Because a PageSetupDialog needs page settings to display, you need to set the Document, PrinterSettings, or PageSettings property before calling ShowDialog; otherwise, an exception will occur.

The following code example demonstrates the PageSetupDialog using the PageSettings, PrinterSettings, and ShowNetwork properties. To run this example, place it in a form containing a Button named Button1, a ListBox named ListBox1, and a PageSetupDialog named PageSetupDialog1. Ensure the button's click event is connected to the event-handling method in this example.


'This method displays a PageSetupDialog object. If the 
' user clicks OK in the dialog, selected results of 
' the dialog are displayed in ListBox1. 
Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Initialize the dialog's PrinterSettings property to hold user 
    ' defined printer settings.
    PageSetupDialog1.PageSettings = _
        New System.Drawing.Printing.PageSettings

    ' Initialize dialog's PrinterSettings property to hold user 
    ' set printer settings.
    PageSetupDialog1.PrinterSettings = _
        New System.Drawing.Printing.PrinterSettings

    'Do not show the network in the printer dialog.
    PageSetupDialog1.ShowNetwork = False 

    'Show the dialog storing the result. 
    Dim result As DialogResult = PageSetupDialog1.ShowDialog()

    ' If the result is OK, display selected settings in 
    ' ListBox1. These values can be used when printing the 
    ' document. 
    If (result = DialogResult.OK) Then 
        Dim results() As Object = New Object() _
            {PageSetupDialog1.PageSettings.Margins, _
             PageSetupDialog1.PageSettings.PaperSize, _
             PageSetupDialog1.PageSettings.Landscape, _
             PageSetupDialog1.PrinterSettings.PrinterName, _
             PageSetupDialog1.PrinterSettings.PrintRange}
        ListBox1.Items.AddRange(results)
    End If 

End Sub

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft