This documentation is archived and is not being maintained.

PrintDocument.DefaultPageSettings Property

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

[Visual Basic]
Public Property DefaultPageSettings As PageSettings
[C#]
public PageSettings DefaultPageSettings {get; set;}
[C++]
public: __property PageSettings* get_DefaultPageSettings();
public: __property void set_DefaultPageSettings(PageSettings*);
[JScript]
public function get DefaultPageSettings() : PageSettings;
public function set DefaultPageSettings(PageSettings);

Property Value

A PageSettings that specifies the default page settings for the document.

Remarks

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.

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

Example

[Visual Basic, C#, C++] The following 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.

[Visual Basic, C#, C++] Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

[Visual Basic] 
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    
   

[C#] 
public void Printing()
{
   try
   {
      streamToPrint = new StreamReader (filePath);
      try
      {
         printFont = new Font("Arial", 10);
         PrintDocument pd = new PrintDocument(); 
         pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
         pd.PrinterSettings.PrinterName = printer;
         // Set the page orientation to landscape.
         pd.DefaultPageSettings.Landscape = true;
         pd.Print();
      } 
      finally
      {
         streamToPrint.Close() ;
      }
   } 
   catch(Exception ex)
   { 
      MessageBox.Show(ex.Message);
   }
}


[C++] 
public:
 void Printing()
 {
    try
    {
       streamToPrint = new StreamReader (filePath);
       try
       {
          printFont = new System::Drawing::Font(S"Arial", 10);
          PrintDocument* pd = new PrintDocument(); 
          pd->PrintPage += new PrintPageEventHandler(this, &Form1::pd_PrintPage);
          pd->PrinterSettings->PrinterName = printer;
          // Set the page orientation to landscape.
          pd->DefaultPageSettings->Landscape = true;
          pd->Print();
       } 
       __finally
       {
          streamToPrint->Close() ;
       }
    } 
    catch(Exception* ex)
    { 
       MessageBox::Show(ex->Message);
    }
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

PrintDocument Class | PrintDocument Members | System.Drawing.Printing Namespace | PageSettings | PrintController | PrinterSettings

Show: