Export (0) Print
Expand All

PageSettings.PaperSize Property

Gets or sets the paper size for the page.

Namespace: System.Drawing.Printing
Assembly: System.Drawing (in system.drawing.dll)

public PaperSize PaperSize { get; set; }
/** @property */
public PaperSize get_PaperSize ()

/** @property */
public void set_PaperSize (PaperSize value)

public function get PaperSize () : PaperSize

public function set PaperSize (value : PaperSize)

Not applicable.

Property Value

A PaperSize that represents the size of the paper. The default is the printer's default paper size.

Exception typeCondition

InvalidPrinterException

The printer named in the PrinterSettings.PrinterName property does not exist or there is no default printer installed.

A PaperSize represents the size of the paper through the PaperSize.Kind property, which contains one of the PaperKind values.

Set the PaperSize property for the page to a valid PaperSize, available through the PrinterSettings.PaperSizes collection.

For information about how you can specify a custom paper size, see the PaperSize constructor.

The following code example sets three properties for the document's default page, including the paper size based upon the size selected in the comboPaperSize combo box, and then prints the document using the Print method. The example requires that a PrintDocument variable named printDoc exists and that the specific combo boxes exist.

private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
    // Set the paper size based upon the selection in the combo box.
    if (comboPaperSize.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSize = 
            printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
    }

    // Set the paper source based upon the selection in the combo box.
    if (comboPaperSource.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSource = 
            printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
    }
    
    // Set the printer resolution based upon the selection in the combo box.
    if (comboPrintResolution.SelectedIndex != -1) 
    {
        printDoc.DefaultPageSettings.PrinterResolution= 
            printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
    }

    // Print the document with the specified paper size, source, and print resolution.
    printDoc.Print();
}

private void myButtonPrint_Click(Object sender, System.EventArgs e)
{
    // Set the paper size based upon the selection in the combo box.
    if (comboPaperSize.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PaperSize(printDoc.
            get_PrinterSettings().get_PaperSizes().
            get_Item(comboPaperSize.get_SelectedIndex()));
    }
    // Set the paper source based upon the selection in the combo box.
    if (comboPaperSource.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PaperSource(printDoc.
            get_PrinterSettings().get_PaperSources().
            get_Item(comboPaperSource.get_SelectedIndex()));
    }
    // Set the printer resolution based upon the selection in the combo box.
    if (comboPrintResolution.get_SelectedIndex() != -1) {
        printDoc.get_DefaultPageSettings().set_PrinterResolution(printDoc.
            get_PrinterSettings().get_PrinterResolutions().
            get_Item(comboPrintResolution.get_SelectedIndex()));
    }
    // Print the document with the specified paper size, source,
    // and print resolution.
    printDoc.Print();
} //myButtonPrint_Click

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft