Export (0) Print
Expand All

PrintDocument.DefaultPageSettings Property

Gets or sets page settings that are used as defaults for all pages to be printed.

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

'Declaration
<BrowsableAttribute(False)> _
Public Property DefaultPageSettings As PageSettings

Property Value

Type: System.Drawing.Printing.PageSettings
A PageSettings that specifies the default page settings for the document.

You can specify several default page settings through the DefaultPageSettings property. For example, the PageSettings.Color property specifies whether the page prints in color, the PageSettings.Landscape property specifies landscape or portrait orientation, and the PageSettings.Margins property specifies the margins of the page.

To specify settings on a page-by-page basis, handle the PrintPage or QueryPageSettings event and modify the PageSettings argument included in the PrintPageEventArgs or QueryPageSettingsEventArgs, respectively.

NoteNote

After printing has started, changes to page settings through the DefaultPageSettings property will not affect pages being printed.

The following code example sets a document's page orientation to landscape, and prints the document. The example makes three assumptions: that a variable named filePath has been set to the path of the file to print; that a method named pd_PrintPage, which handles the PrintPage event, has been defined; and that a variable named printer has been set to the printer's name.

Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

Public Sub Printing()
    Try
        streamToPrint = New StreamReader(filePath)
        Try
            printFont = New Font("Arial", 10)
            Dim pd As New PrintDocument()
            AddHandler pd.PrintPage, AddressOf pd_PrintPage
            pd.PrinterSettings.PrinterName = printer
            ' Set the page orientation to landscape.
            pd.DefaultPageSettings.Landscape = True
            pd.Print()
        Finally
            streamToPrint.Close()
        End Try 
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try 
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.

Show:
© 2014 Microsoft