PrinterSettings 類別

定義

指定從 Windows Form 應用程式列印時,文件如何列印的相關資訊,包括用來列印的印表機。

public ref class PrinterSettings : ICloneable
public class PrinterSettings : ICloneable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class PrinterSettings : ICloneable
[System.Serializable]
public class PrinterSettings : ICloneable
type PrinterSettings = class
    interface ICloneable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type PrinterSettings = class
    interface ICloneable
[<System.Serializable>]
type PrinterSettings = class
    interface ICloneable
Public Class PrinterSettings
Implements ICloneable
繼承
PrinterSettings
屬性
實作

範例

下列程式代碼範例會在指定的印表機上列印檔。 此範例有三個必要條件:

  • 名為 filePath 的變數已設定為要列印的檔案路徑。

  • 已定義名為 pd_PrintPage的方法,這個方法會處理 PrintPage 事件。

  • 名為 printer 的變數已設定為印表機的名稱。

針對此範例, System.Drawing請使用、 System.Drawing.PrintingSystem.IO 命名空間。

public:
   void Printing( String^ printer )
   {
      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;
            if ( pd->PrinterSettings->IsValid )
            {
               pd->Print();
            }
            else
            {
               MessageBox::Show( "Printer is invalid." );
            }
         }
         finally
         {
            streamToPrint->Close();
         }
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( ex->Message );
      }
   }
public void Printing(string printer) {
  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;

      if (pd.PrinterSettings.IsValid) {
         pd.Print();
      } 
      else {	
         MessageBox.Show("Printer is invalid.");
      }
    } 
    finally {
      streamToPrint.Close();
    }
  } 
  catch(Exception ex) {
    MessageBox.Show(ex.Message);
  }
}
Public Sub Printing(printer As String)
    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

            If pd.PrinterSettings.IsValid then
               pd.Print()
            Else
               MessageBox.Show("Printer is invalid.")
            End If
        Finally
            streamToPrint.Close()
        End Try
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

備註

一般而言,您可以透過 PrintDocument.PrinterSettingsPageSettings.PrinterSettings 屬性存取 PrinterSettings 來修改印表機設定。 最常見的印表機設定是 PrinterName,指定要列印的印表機。

如需使用 Windows Forms 列印的詳細資訊,請參閱System.Drawing.Printing命名空間概觀。 如果您想要從 Windows Presentation Foundation 應用程式列印,請參閱 System.Printing 命名空間。

注意

在 .NET 6 和更新版本中,只有 Windows 作業系統才支援包含此類型的 System.Drawing.Common 套件。 在跨平臺應用程式中使用此類型會導致編譯時期警告和運行時間例外狀況。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common

建構函式

PrinterSettings()

初始化 PrinterSettings 類別的新執行個體。

屬性

CanDuplex

取得值,指出印表機是否支援雙面列印。

Collate

取得或設定值,指出列印文件是否要分頁。

Copies

取得或設定文件列印的份數。

DefaultPageSettings

取得這個印表機的預設頁面設定。

Duplex

取得或設定雙面列印的印表機設定。

FromPage

取得或設定要列印的第一頁的頁碼。

InstalledPrinters

取得安裝於電腦上的所有印表機名稱。

IsDefaultPrinter

取得值,指出 PrinterName 屬性是否會指定預設的印表機 (除非使用者明確設定 PrinterName)。

IsPlotter

取得值,指出印表機是否為繪圖機。

IsValid

取得值,指出 PrinterName 屬性是否指定有效印表機。

LandscapeAngle

以度數為單位,取得將縱向列印旋轉以產生橫向列印的角度。

MaximumCopies

取得印表機可讓使用者單次列印的最大複本數目。

MaximumPage

取得或設定可在 FromPage 內選取的最大 ToPagePrintDialog

MinimumPage

取得或設定可在 FromPage 內選取的最小 ToPagePrintDialog

PaperSizes

取得這個印表機支援的紙張大小。

PaperSources

取得印表機可用的紙張來源紙匣。

PrinterName

取得或設定要使用的印表機名稱。

PrinterResolutions

取得這個印表機支援的所有解析度。

PrintFileName

取得或設定列印至檔案時的檔案名稱。

PrintRange

取得或設定使用者指定要列印的頁碼。

PrintToFile

取得或設定值,指出列印輸出是否傳送至檔案而非連接埠。

SupportsColor

取得值,指出這個印表機是否支援彩色列印。

ToPage

取得或設定要列印的最後一頁的頁碼。

方法

Clone()

建立這個 PrinterSettings 的複本。

CreateMeasurementGraphics()

傳回 Graphics,其中包含在建立 PrintDocument 時非常有用的印表機資訊。

CreateMeasurementGraphics(Boolean)

傳回包含印表機資訊的 Graphics,選擇性地指定邊界處的原點。

CreateMeasurementGraphics(PageSettings)

傳回 Graphics,其中包含與指定之 PageSettings 關聯的印表機資訊。

CreateMeasurementGraphics(PageSettings, Boolean)

建立與指定頁面設定關聯的 Graphics,並選擇性地指定邊界處的原點。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetHdevmode()

建立對應到印表機設定的 DEVMODE 結構的控制代碼。

GetHdevmode(PageSettings)

建立對應於印表機的 DEVMODE 結構控制代碼和透過 pageSettings 參數指定的頁面設定。

GetHdevnames()

建立對應到印表機設定的 DEVNAMES 結構的控制代碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDirectPrintingSupported(Image)

取得值,指示印表機是否支援列印指定的影像檔。

IsDirectPrintingSupported(ImageFormat)

傳回值,指示印表機是否支援列印指定的影像格式。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
SetHdevmode(IntPtr)

複製已給定的控制代碼以外的相關資訊至 PrinterSettings

SetHdevnames(IntPtr)

複製已給定的控制代碼以外的相關資訊至 PrinterSettings

ToString()

以字串形式提供 PrinterSettings 的相關資訊。

適用於

另請參閱