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)

public PageSettings DefaultPageSettings { get; set; }
/** @property */
public PageSettings get_DefaultPageSettings ()

/** @property */
public void set_DefaultPageSettings (PageSettings value)

public function get DefaultPageSettings () : PageSettings

public function set DefaultPageSettings (value : PageSettings)

Not applicable.

Property Value

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


public void Printing()
{
    try {
        streamToPrint = new StreamReader(filePath);
        try {
            printFont = new Font("Arial", 10);
            PrintDocument pd = new PrintDocument();
            pd.add_PrintPage(new PrintPageEventHandler(pd_PrintPage));
            pd.get_PrinterSettings().set_PrinterName(printer);

            // Set the page orientation to landscape.
            pd.get_DefaultPageSettings().set_Landscape(true);
            pd.Print();
        }
        finally {
            streamToPrint.Close();
        }
    }
    catch (System.Exception ex) {
        MessageBox.Show(ex.get_Message());
    }
} //Printing

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:
© 2015 Microsoft