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 Value

Type: System.Drawing.Printing.PaperSize
A PaperSize that represents the size of the paper. The default is the printer's default paper size.

ExceptionCondition
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.

            // Add list of supported paper sizes found on the printer.  
            // The DisplayMember property is used to identify the property that will provide the display string.
            comboPaperSize.DisplayMember = "PaperName";

            PaperSize pkSize;
            for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){
                pkSize = printDoc.PrinterSettings.PaperSizes[i];
                comboPaperSize.Items.Add(pkSize);
            }

            // Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
            PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);

            comboPaperSize.Items.Add(pkCustomSize1);



...


// Add list of paper sources found on the printer to the combo box. 
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSource.DisplayMember="SourceName";

PaperSource pkSource;
for (int i = 0; i < printDoc.PrinterSettings.PaperSources.Count; i++){
    pkSource = printDoc.PrinterSettings.PaperSources[i];
    comboPaperSource.Items.Add(pkSource);
}


...


// Add list of printer resolutions found on the printer to the combobox. 
// The PrinterResolution's ToString() method will be used to provide the display string.

PrinterResolution pkResolution;
for (int i = 0; i < printDoc.PrinterSettings.PrinterResolutions.Count; i++){
    pkResolution = printDoc.PrinterSettings.PrinterResolutions[i];
    comboPrintResolution.Items.Add(pkResolution);
}


...


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();
}

.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.

Show:
© 2014 Microsoft