PrintDocument.DefaultPageSettings 属性

定义

获取或设置用作要打印的所有页的默认设置的页设置。Gets or sets page settings that are used as defaults for all pages to be printed.

public:
 property System::Drawing::Printing::PageSettings ^ DefaultPageSettings { System::Drawing::Printing::PageSettings ^ get(); void set(System::Drawing::Printing::PageSettings ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PageSettings DefaultPageSettings { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.DefaultPageSettings : System.Drawing.Printing.PageSettings with get, set
Public Property DefaultPageSettings As PageSettings

属性值

PageSettings

为文档指定默认页设置的 PageSettingsA PageSettings that specifies the default page settings for the document.

属性

示例

下面的代码示例将文档的页面方向设置为横向,并打印文档。The following code example sets a document's page orientation to landscape, and prints the document. 该示例进行了三个假设:已将一个名为的变量 filePath 设置为要打印的文件的路径; 已经定义了一个名为的方法,该方法 pd_PrintPage 处理 PrintPage 事件,并已将名为的变量 printer 设置为打印机的名称。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.

System.Drawing 此示例中使用、 System.Drawing.PrintingSystem.IO 命名空间。Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

public:
   void Printing()
   {
      try
      {
         streamToPrint = gcnew StreamReader( filePath );
         try
         {
            printFont = gcnew System::Drawing::Font( "Arial",10 );
            PrintDocument^ pd = gcnew PrintDocument;
            pd->PrintPage += gcnew 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 );
      }
   }
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 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    
   

注解

您可以通过属性指定多个默认页面设置 DefaultPageSettingsYou can specify several default page settings through the DefaultPageSettings property. 例如, PageSettings.Color 属性指定是否以彩色打印页面, PageSettings.Landscape 属性指定横向或纵向方向, PageSettings.Margins 属性指定页面的边距。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.

若要逐页指定设置,请 PrintPage 分别处理或 QueryPageSettings 事件,并修改 PageSettings 或中包含的参数 PrintPageEventArgs QueryPageSettingsEventArgsTo 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.

备注

开始打印后,通过属性对页面设置的更改 DefaultPageSettings 将不会影响要打印的页面。After printing has started, changes to page settings through the DefaultPageSettings property will not affect pages being printed.

适用于

另请参阅