PrinterSettings 类

定义

指定有关在从 Windows 窗体应用程序打印时如何打印文档的信息,包括打印文档的打印机。Specifies information about how a document is printed, including the printer that prints it, when printing from a Windows Forms application.

public ref class PrinterSettings : ICloneable
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class PrinterSettings : ICloneable
type PrinterSettings = class
    interface ICloneable
Public Class PrinterSettings
Implements ICloneable
继承
PrinterSettings
属性
实现

示例

下面的代码示例在指定的打印机上打印文档。The following code example prints a document on the specified printer. 该示例有三个先决条件:The example has three prerequisites:

  • 名为 filePath 的变量已设置为要打印的文件的路径。A variable named filePath has been set to the path of the file to print.

  • 已经定义了一个名为 pd_PrintPage的方法,该方法处理 PrintPage 事件。A method named pd_PrintPage, which handles the PrintPage event, has been defined.

  • 已将名为 printer 的变量设置为打印机的名称。A variable named printer has been set to the printer's name.

对于本示例,请使用 System.DrawingSystem.Drawing.PrintingSystem.IO 命名空间。Use the System.Drawing, System.Drawing.Printing, and System.IO namespaces for this example.

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 来修改打印机设置。Typically, you access a PrinterSettings through PrintDocument.PrinterSettings or PageSettings.PrinterSettings properties to modify printer settings. 最常见的打印机设置为 PrinterName,它指定要打印到的打印机。The most common printer setting is PrinterName, which specifies the printer to print to.

有关 Windows 窗体打印的详细信息,请参阅 System.Drawing.Printing 命名空间概述。For more information about printing with Windows Forms, see the System.Drawing.Printing namespace overview. 如果要从 Windows Presentation Foundation 应用程序打印,请参阅 System.Printing 命名空间。If you wish to print from a Windows Presentation Foundation application, see the System.Printing namespace.

构造函数

PrinterSettings()

初始化 PrinterSettings 类的新实例。Initializes a new instance of the PrinterSettings class.

属性

CanDuplex

获取指示打印机是否支持双面打印的值。Gets a value indicating whether the printer supports double-sided printing.

Collate

获取或设置一个值,该值指示打印文档是否逐份打印。Gets or sets a value indicating whether the printed document is collated.

Copies

获取或设置要打印的文档份数。Gets or sets the number of copies of the document to print.

DefaultPageSettings

获取此打印机的默认页设置。Gets the default page settings for this printer.

Duplex

获取或设置双面打印的打印机设置。Gets or sets the printer setting for double-sided printing.

FromPage

获取或设置要打印的第一页的页码。Gets or sets the page number of the first page to print.

InstalledPrinters

获取安装在计算机上所有打印机的名称。Gets the names of all printers installed on the computer.

IsDefaultPrinter

获取一个值,该值指示 PrinterName 属性是否指定默认打印机(用户显式设置 PrinterName 的情况除外)。Gets a value indicating whether the PrinterName property designates the default printer, except when the user explicitly sets PrinterName.

IsPlotter

获取指示该打印机是否是绘图仪的值。Gets a value indicating whether the printer is a plotter.

IsValid

获取一个值,该值指示 PrinterName 属性是否指定了有效的打印机。Gets a value indicating whether the PrinterName property designates a valid printer.

LandscapeAngle

获取旋转纵向方向以生成横向方向的角度,以度为单位。Gets the angle, in degrees, that the portrait orientation is rotated to produce the landscape orientation.

MaximumCopies

获取打印机允许用户一次打印的最大份数。Gets the maximum number of copies that the printer enables the user to print at a time.

MaximumPage

获取或设置可以在 FromPage 中选定的最大的 ToPagePrintDialogGets or sets the maximum FromPage or ToPage that can be selected in a PrintDialog.

MinimumPage

获取或设置可以在 FromPage 中选定的最小的 ToPagePrintDialogGets or sets the minimum FromPage or ToPage that can be selected in a PrintDialog.

PaperSizes

获取该打印机支持的纸张大小。Gets the paper sizes that are supported by this printer.

PaperSources

获取打印机上可用的纸张来源纸盒。Gets the paper source trays that are available on the printer.

PrinterName

获取或设置要使用的打印机的名称。Gets or sets the name of the printer to use.

PrinterResolutions

获取该打印机支持的所有分辨率。Gets all the resolutions that are supported by this printer.

PrintFileName

打印到文件时,获取或设置文件名。Gets or sets the file name, when printing to a file.

PrintRange

获取或设置用户已指定要打印的页码。Gets or sets the page numbers that the user has specified to be printed.

PrintToFile

获取或设置一个值,该值指示打印输出是否发送到文件,而不发送到端口。Gets or sets a value indicating whether the printing output is sent to a file instead of a port.

SupportsColor

获取指示该打印机是否支持彩色打印的值。Gets a value indicating whether this printer supports color printing.

ToPage

获取或设置要打印的最后一页的页码。Gets or sets the number of the last page to print.

方法

Clone()

创建此 PrinterSettings 的副本。Creates a copy of this PrinterSettings.

CreateMeasurementGraphics()

返回 Graphics,它包含创建 PrintDocument 时有用的打印机信息。Returns a Graphics that contains printer information that is useful when creating a PrintDocument.

CreateMeasurementGraphics(Boolean)

返回包含打印机信息的 Graphics,选择性地指定边距处的原点。Returns a Graphics that contains printer information, optionally specifying the origin at the margins.

CreateMeasurementGraphics(PageSettings)

返回 Graphics,包含与指定 PageSettings 关联的打印机信息。Returns a Graphics that contains printer information associated with the specified PageSettings.

CreateMeasurementGraphics(PageSettings, Boolean)

创建与指定页设置关联的 Graphics 并选择性地指定边距处的原点。Creates a Graphics associated with the specified page settings and optionally specifying the origin at the margins.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetHdevmode()

创建与打印机设置相对应的 DEVMODE 结构的句柄。Creates a handle to a DEVMODE structure that corresponds to the printer settings.

GetHdevmode(PageSettings)

创建一个 DEVMODE 结构的句柄,它对应于通过 pageSettings 参数指定的打印机和页设置。Creates a handle to a DEVMODE structure that corresponds to the printer and the page settings specified through the pageSettings parameter.

GetHdevnames()

创建与打印机设置相对应的 DEVNAMES 结构的句柄。Creates a handle to a DEVNAMES structure that corresponds to the printer settings.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDirectPrintingSupported(Image)

获取一个值,该值指示打印机是否支持打印指定的图像文件。Gets a value indicating whether the printer supports printing the specified image file.

IsDirectPrintingSupported(ImageFormat)

返回一个值,该值指示打印机是否支持打印指定的图像格式。Returns a value indicating whether the printer supports printing the specified image format.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetHdevmode(IntPtr)

将相关信息从给定句柄复制到 PrinterSettings 中。Copies the relevant information out of the given handle and into the PrinterSettings.

SetHdevnames(IntPtr)

将相关信息从给定句柄复制到 PrinterSettings 中。Copies the relevant information out of the given handle and into the PrinterSettings.

ToString()

以字符串形式提供有关 PrinterSettings 的信息。Provides information about the PrinterSettings in string form.

适用于

另请参阅