System.Drawing.Printing Namespace

System.Drawing.Printing 命名空间为 Windows 窗体应用程序提供与打印相关的服务。 The System.Drawing.Printing namespace provides print-related services for Windows Forms applications.

Classes

InvalidPrinterException

表示当尝试用无效的打印机设置来访问打印机时所引发的异常。Represents the exception that is thrown when you try to access a printer using printer settings that are not valid.

Margins

指定打印页的边距尺寸。Specifies the dimensions of the margins of a printed page.

MarginsConverter

MarginsConverter 提供一个 MarginsProvides a MarginsConverter for Margins.

PageSettings

指定应用于单页打印的设置。Specifies settings that apply to a single, printed page.

PaperSize

指定纸张大小。Specifies the size of a piece of paper.

PaperSource

指定给打印机送纸的纸盒。Specifies the paper tray from which the printer gets paper.

PreviewPageInfo

为单页指定打印预览信息。Specifies print preview information for a single page. 此类不能被继承。This class cannot be inherited.

PreviewPrintController

指定一个打印控制器,它在屏幕上将文档显示为一系列图像。Specifies a print controller that displays a document on a screen as a series of images.

PrintController

控制在从 Windows 窗体应用程序打印时如何打印文档。Controls how a document is printed, when printing from a Windows Forms application.

PrintDocument

从 Windows 窗体应用程序打印时,定义一种可重用的可发送到打印机上的对象。Defines a reusable object that sends output to a printer, when printing from a Windows Forms application.

PrinterResolution

表示打印机支持的分辨率。Represents the resolution supported by a printer.

PrinterSettings

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

PrinterSettings.PaperSizeCollection

包含 PaperSize 对象的集合。Contains a collection of PaperSize objects.

PrinterSettings.PaperSourceCollection

包含 PaperSource 对象的集合。Contains a collection of PaperSource objects.

PrinterSettings.PrinterResolutionCollection

包含 PrinterResolution 对象的集合。Contains a collection of PrinterResolution objects.

PrinterSettings.StringCollection

包含 String 对象的集合。Contains a collection of String objects.

PrinterUnitConvert

指定一系列与 Win32 打印 API 互操作时非常有用的转换方法。Specifies a series of conversion methods that are useful when interoperating with the Win32 printing API. 无法继承此类。This class cannot be inherited.

PrintEventArgs

提供有关 BeginPrintEndPrint 事件的数据。Provides data for the BeginPrint and EndPrint events.

PrintingPermission

控制对打印机的访问。Controls access to printers. 此类不能被继承。This class cannot be inherited.

PrintingPermissionAttribute

允许进行声明打印权限检查。Allows declarative printing permission checks.

PrintPageEventArgs

PrintPage 事件提供数据。Provides data for the PrintPage event.

QueryPageSettingsEventArgs

QueryPageSettings 事件提供数据。Provides data for the QueryPageSettings event.

StandardPrintController

指定一个打印控制器,它向打印机发送信息。Specifies a print controller that sends information to a printer.

Enums

Duplex

指定打印机的双面打印设置。Specifies the printer's duplex setting.

PaperKind

指定标准纸张大小。Specifies the standard paper sizes.

PaperSourceKind

标准的纸张来源。Standard paper sources.

PrintAction

指定正在进行的打印操作的类型。Specifies the type of print operation occurring.

PrinterResolutionKind

指定打印机的分辨率。Specifies a printer resolution.

PrinterUnit

指定几个用于打印的度量单位。Specifies several of the units of measure used for printing.

PrintingPermissionLevel

指定允许代码进行的打印类型。Specifies the type of printing that code is allowed to do.

PrintRange

指定要打印的文档部分。Specifies the part of the document to print.

Delegates

PrintEventHandler

表示将对 BeginPrintEndPrintPrintDocument 事件进行处理的方法。Represents the method that will handle the BeginPrint or EndPrint event of a PrintDocument.

PrintPageEventHandler

表示将处理 PrintDocumentPrintPage 事件的方法。Represents the method that will handle the PrintPage event of a PrintDocument.

QueryPageSettingsEventHandler

表示处理 PrintDocumentQueryPageSettings 事件的方法。Represents the method that handles the QueryPageSettings event of a PrintDocument.

Remarks

通常,从 Windows 窗体应用程序打印时,将创建 PrintDocument 类的新实例,设置用于描述如何打印的属性,如 DefaultPageSettingsPrinterSettings,并调用 Print 方法以实际打印文档。Typically, when you print from a Windows Forms application, you create a new instance of the PrintDocument class, set properties, such as DefaultPageSettings and PrinterSettings, that describe how to print, and call the Print method to actually print the document. 调用 PrintDocument.Print 方法将引发 PrintDocument.PrintPage 事件,应对该事件进行处理以执行打印的文档布局。Calling the PrintDocument.Print method raises the PrintDocument.PrintPage event, which should be handled to perform the document layout for printing.

使用从 PrintDocument.PrintPage 事件获取的 PrintPageEventArgs 对象的 Graphics 属性指定要打印的输出。Use the Graphics property of the PrintPageEventArgs object obtained from the PrintDocument.PrintPage event to specify the output to print. 如果要打印文本文件,请使用 StreamReader 从流中一次读取一行,并调用 DrawString 方法在图形对象中绘制线条。If you are printing a text file, use StreamReader to read one line at a time from the stream and call the DrawString method to draw the line in the graphics object. 有关此过程的详细信息,请参阅 GraphicsStreamReader 类。For more information about this process, see the Graphics and StreamReader classes. 您可以在 PrintDocument 类概述主题中查看打印文本文档的示例。You can view an example of printing a text document in the PrintDocument class overview topic.

Note

打印不支持 TextRenderer 类的 DrawText 方法。The DrawText methods of the TextRenderer class are not supported for printing. 请改用 Graphics 类的 DrawString 方法。Instead, use the DrawString methods of the Graphics class.

在派生类中实现时,PrintController 控制如何打印 PrintDocumentWhen implemented in a derived class, the PrintController controls how a PrintDocument is printed. PrintDocument.Print 方法调用打印控制器的 OnStartPrintOnEndPrintOnStartPageOnEndPage 方法,这进而告诉打印机如何打印文档。The PrintDocument.Print method invokes the print controller's OnStartPrint, OnEndPrint, OnStartPage, and OnEndPage methods, which in turn tell the printer how to print the document. 有关打印对话框的详细信息,请参阅 PrintDialogPageSetupDialogFor more information about printing dialog boxes, see PrintDialog and PageSetupDialog.

打印预览过程使用专用的打印控制器、对话框和控件。The print-preview process uses a specialized print controller, dialog box, and control. 有关此类打印控制器和对话框的示例,请参阅 PreviewPrintControllerPrintPreviewDialogPrintPreviewControlFor an example of such a print controller and dialog box, see PreviewPrintController, PrintPreviewDialog, and PrintPreviewControl.

Caution

不支持在 Windows 服务或 ASP.NET 应用程序或服务中使用 System.Drawing.Printing 命名空间中的类。Classes within the System.Drawing.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. 尝试从这些应用程序类型之一中使用这些类可能会产生意外的问题,例如降低服务性能和运行时异常。Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

如果要从 Windows Presentation Foundation (WPF)应用程序进行打印,请参阅 System.Printing 命名空间。If you want to print from a Windows Presentation Foundation (WPF) application, see the System.Printing namespace.

See also