PrintDocument.PrinterSettings 属性

定义

获取或设置对文档进行打印的打印机。

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

属性值

PrinterSettings,它指定在何处以及如何打印文档。 默认为 PrinterSettings,其属性均设置为默认值。

属性

示例

下面的代码示例在指定的打印机上打印文档。 该示例假设有三个假设:变量名称 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 );
            // Specify the printer to use.
            pd->PrinterSettings->PrinterName = printer;
            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);
        // Specify the printer to use.
        pd.PrinterSettings.PrinterName = printer;
        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
            ' Specify the printer to use.
            pd.PrinterSettings.PrinterName = printer
            pd.Print()
        Finally
               streamToPrint.Close()
        End Try
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

注解

可以通过 属性指定多个打印机设置 PrinterSettings 。 例如,使用 PrinterSettings.Copies 属性指定要打印的份数, PrinterSettings.PrinterName 使用 属性指定要使用的打印机,并使用 PrinterSettings.PrintRange 属性指定要打印的页范围。

适用于

另请参阅