共用方式為


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 指定要列印的頁面範圍屬性。

適用於

另請參閱