PageSetupDialog PageSetupDialog PageSetupDialog PageSetupDialog Class

Definition

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

public ref class PageSetupDialog sealed : System::Windows::Forms::CommonDialog
public sealed class PageSetupDialog : System.Windows.Forms.CommonDialog
type PageSetupDialog = class
    inherit CommonDialog
Public NotInheritable Class PageSetupDialog
Inherits CommonDialog
Inheritance

Examples

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.
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   
   // Initialize the dialog's PrinterSettings property to hold user
   // defined printer settings.
   PageSetupDialog1->PageSettings = gcnew System::Drawing::Printing::PageSettings;
   
   // Initialize dialog's PrinterSettings property to hold user
   // set printer settings.
   PageSetupDialog1->PrinterSettings = gcnew System::Drawing::Printing::PrinterSettings;
   
   //Do not show the network in the printer dialog.
   PageSetupDialog1->ShowNetwork = false;
   
   //Show the dialog storing the result.
   System::Windows::Forms::DialogResult result = 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 )
   {
      array<Object^>^results = {PageSetupDialog1->PageSettings->Margins,PageSetupDialog1->PageSettings->PaperSize,PageSetupDialog1->PageSettings->Landscape,PageSetupDialog1->PrinterSettings->PrinterName,PageSetupDialog1->PrinterSettings->PrintRange};
      ListBox1->Items->AddRange( results );
   }
   
}

//This method displays a PageSetupDialog object. If the
// user clicks OK in the dialog, selected results of
// the dialog are displayed in ListBox1.
   private void Button1_Click(System.Object sender, System.EventArgs e)
   {

       // 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.
       DialogResult result = 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)
       {
           object[] results = new object[]{ 
			PageSetupDialog1.PageSettings.Margins, 
			PageSetupDialog1.PageSettings.PaperSize, 
			PageSetupDialog1.PageSettings.Landscape, 
			PageSetupDialog1.PrinterSettings.PrinterName, 
			PageSetupDialog1.PrinterSettings.PrintRange};
           ListBox1.Items.AddRange(results);
       }
      
   }

'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

Remarks

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.

Constructors

PageSetupDialog() PageSetupDialog() PageSetupDialog() PageSetupDialog()

Initializes a new instance of the PageSetupDialog class.

Properties

AllowMargins AllowMargins AllowMargins AllowMargins

Gets or sets a value indicating whether the margins section of the dialog box is enabled.

AllowOrientation AllowOrientation AllowOrientation AllowOrientation

Gets or sets a value indicating whether the orientation section of the dialog box (landscape versus portrait) is enabled.

AllowPaper AllowPaper AllowPaper AllowPaper

Gets or sets a value indicating whether the paper section of the dialog box (paper size and paper source) is enabled.

AllowPrinter AllowPrinter AllowPrinter AllowPrinter

Gets or sets a value indicating whether the Printer button is enabled.

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

Gets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Document Document Document Document

Gets or sets a value indicating the PrintDocument to get page settings from.

EnableMetric EnableMetric EnableMetric EnableMetric

Gets or sets a value indicating whether the margin settings, when displayed in millimeters, should be automatically converted to and from hundredths of an inch.

Events Events Events Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
MinMargins MinMargins MinMargins MinMargins

Gets or sets a value indicating the minimum margins, in hundredths of an inch, the user is allowed to select.

PageSettings PageSettings PageSettings PageSettings

Gets or sets a value indicating the page settings to modify.

PrinterSettings PrinterSettings PrinterSettings PrinterSettings

Gets or sets the printer settings that are modified when the user clicks the Printer button in the dialog.

ShowHelp ShowHelp ShowHelp ShowHelp

Gets or sets a value indicating whether the Help button is visible.

ShowNetwork ShowNetwork ShowNetwork ShowNetwork

Gets or sets a value indicating whether the Network button is visible.

Site Site Site Site

Gets or sets the ISite of the Component.

(Inherited from Component)
Tag Tag Tag Tag

Gets or sets an object that contains data about the control.

(Inherited from CommonDialog)

Methods

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr) HookProc(IntPtr, Int32, IntPtr, IntPtr)

Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.

(Inherited from CommonDialog)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs) OnHelpRequest(EventArgs)

Raises the HelpRequest event.

(Inherited from CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr) OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

Defines the owner window procedure that is overridden to add specific functionality to a common dialog box.

(Inherited from CommonDialog)
Reset() Reset() Reset() Reset()

Resets all options to their default values.

RunDialog(IntPtr) RunDialog(IntPtr) RunDialog(IntPtr) RunDialog(IntPtr)

When overridden in a derived class, specifies a common dialog box.

(Inherited from CommonDialog)
ShowDialog() ShowDialog() ShowDialog() ShowDialog()

Runs a common dialog box with a default owner.

(Inherited from CommonDialog)
ShowDialog(IWin32Window) ShowDialog(IWin32Window) ShowDialog(IWin32Window) ShowDialog(IWin32Window)

Runs a common dialog box with the specified owner.

(Inherited from CommonDialog)
ToString() ToString() ToString() ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)

Events

Disposed Disposed Disposed Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
HelpRequest HelpRequest HelpRequest HelpRequest

Occurs when the user clicks the Help button on a common dialog box.

(Inherited from CommonDialog)

Applies to

See Also