Op Englesch liesen Editéieren

Deelen iwwer


PrintDocument.DefaultPageSettings Property

Definition

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

C#
[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PageSettings DefaultPageSettings { get; set; }

Property Value

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

Attributes

Examples

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.

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

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.

Notiz

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

Applies to

Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also