PrinterSettings 类

定义

指定有关在从 Windows 窗体应用程序打印时如何打印文档的信息,包括打印文档的打印机。

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

注解

通常,通过 PrinterSettingsPrintDocument.PrinterSettings 访问 或 PageSettings.PrinterSettings 属性以修改打印机设置。 最常见的打印机设置是 PrinterName,它指定要打印到的打印机。

有关使用 Windows 窗体 打印的详细信息,请参阅System.Drawing.Printing命名空间概述。 如果要从Windows Presentation Foundation应用程序打印,请参阅 System.Printing 命名空间。

备注

在 .NET 6 及更高版本中, System.Drawing.Common 包(包括此类型)仅在 Windows 操作系统上受支持。 在跨平台应用中使用此类型会导致编译时警告和运行时异常。 有关详细信息,请参阅 仅在 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 的信息。

适用于

另请参阅