Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
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)
Visual Basic (Declaration)
Public NotInheritable Class PageSetupDialog _
    Inherits CommonDialog
Visual Basic (Usage)
Dim instance As PageSetupDialog
C#
public sealed class PageSetupDialog : CommonDialog
Visual C++
public ref class PageSetupDialog sealed : public CommonDialog
JScript
public final class PageSetupDialog extends CommonDialog

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.

Visual Basic
'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

C#
    //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);
        }

    }

Visual C++
//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 );
   }

}

System..::.Object
  System..::.MarshalByRefObject
    System.ComponentModel..::.Component
      System.Windows.Forms..::.CommonDialog
        System.Windows.Forms..::.PageSetupDialog
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker