PrintDocument.DefaultPageSettings 属性

定义

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

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

属性值

为文档指定默认页设置的 PageSettings

属性

示例

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

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

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

注解

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

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

备注

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

适用于

产品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅