PrintDocument.DefaultPageSettings 属性

定义

获取或设置用作要打印的所有页的默认设置的页设置。

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

属性

示例

下面的代码示例将文档的页面方向设置为横向,并打印文档。 该示例假设有三个假设:名为 的 filePath 变量已设置为要打印的文件的路径;已定义一个名为 pd_PrintPage的方法,用于处理 PrintPage 事件;已将名为 的 printer 变量设置为打印机的名称。

对于此示例, System.Drawing请使用 、 System.Drawing.PrintingSystem.IO 命名空间。

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

注解

可以通过 属性指定多个默认页面设置 DefaultPageSettings 。 例如, PageSettings.Color 属性指定页面是彩色打印,属性 PageSettings.Landscape 指定横向还是纵向,属性 PageSettings.Margins 指定页边距。

若要逐页指定设置,请分别处理 PrintPageQueryPageSettings 事件并修改 PageSettingsQueryPageSettingsEventArgs中包含的PrintPageEventArgs参数。

备注

打印开始后,通过 DefaultPageSettings 属性更改页面设置不会影响正在打印的页面。

适用于

另请参阅