System.Drawing.Printing Namespace

The System.Drawing.Printing namespace provides print-related services for Windows Forms applications.

Remarks

Typically, when you print from a Windows Forms application, you create a new instance of the System.Drawing.Printing.PrintDocument class, set properties, such as System.Drawing.Printing.PrintDocument.DefaultPageSettings and System.Drawing.Printing.PrintDocument.PrinterSettings, that describe how to print, and call the System.Drawing.Printing.PrintDocument.Print method to actually print the document. Calling the System.Drawing.Printing.PrintDocument.Print method raises the System.Drawing.Printing.PrintDocument.PrintPage event, which should be handled to perform the document layout for printing.

Use the System.Drawing.Printing.PrintPageEventArgs.Graphics property of the System.Drawing.Printing.PrintPageEventArgs object obtained from the System.Drawing.Printing.PrintDocument.PrintPage event to specify the output to print. If you are printing a text file, use System.IO.StreamReader to read one line at a time from the stream and call the System.Drawing.Graphics.DrawString(string, System.Drawing.Font, System.Drawing.Brush, System.Drawing.PointF) method to draw the line in the graphics object. For more information about this process, see the System.Drawing.Graphics and System.IO.StreamReader classes. You can view an example of printing a text document in the System.Drawing.Printing.PrintDocument class overview topic.

Note:

The erload:System.Windows.Forms.TextRenderer.DrawText methods of the System.Windows.Forms.TextRenderer class are not supported for printing. Instead, use the erload:System.Drawing.Graphics.DrawString methods of the System.Drawing.Graphics class.

When implemented in a derived class, the System.Drawing.Printing.PrintController controls how a System.Drawing.Printing.PrintDocument is printed. The System.Drawing.Printing.PrintDocument.Print method invokes the print controller's System.Drawing.Printing.PrintController.OnStartPrint(System.Drawing.Printing.PrintDocument, System.Drawing.Printing.PrintEventArgs), System.Drawing.Printing.PrintController.OnEndPrint(System.Drawing.Printing.PrintDocument, System.Drawing.Printing.PrintEventArgs), System.Drawing.Printing.PrintController.OnStartPage(System.Drawing.Printing.PrintDocument, System.Drawing.Printing.PrintPageEventArgs), and System.Drawing.Printing.PrintController.OnEndPage(System.Drawing.Printing.PrintDocument, System.Drawing.Printing.PrintPageEventArgs) methods, which in turn tell the printer how to print the document. For more information about printing dialog boxes, see System.Windows.Forms.PrintDialog and System.Windows.Forms.PageSetupDialog.

The print-preview process uses a specialized print controller, dialog box, and control. For an example of such a print controller and dialog box, see System.Drawing.Printing.PreviewPrintController, System.Windows.Forms.PrintPreviewDialog, and System.Windows.Forms.PrintPreviewControl.

Note:

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.

If you want to print from a Windows Presentation Foundation (WPF) application, see the System.Printing namespace.

Classes

TypeReason
Duplex

Specifies the printer's duplex setting.

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

Provides a System.Drawing.Printing.MarginsConverter for System.Drawing.Printing.Margins.

PageSettings

Specifies settings that apply to a single, printed page.

PaperKind

Specifies the standard paper sizes.

PaperSize

Specifies the size of a piece of paper.

PaperSource

Specifies the paper tray from which the printer gets paper.

PaperSourceKind

Standard paper sources.

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.

PrintAction

Specifies the type of print operation occurring.

PrintController

Controls how a document is printed, when printing from a Windows Forms application.

PrintDocument

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.

PrinterResolutionKind

Specifies a printer resolution.

PrinterSettings

Specifies information about how a document is printed, including the printer that prints it, when printing from a Windows Forms application.

PrinterSettings+PaperSizeCollectionDocumentation for this section has not yet been entered.
PrinterSettings+PaperSourceCollectionDocumentation for this section has not yet been entered.
PrinterSettings+PrinterResolutionCollectionDocumentation for this section has not yet been entered.
PrinterSettings+StringCollectionDocumentation for this section has not yet been entered.
PrinterUnit

Specifies several of the units of measure used for printing.

PrinterUnitConvert

Specifies a series of conversion methods that are useful when interoperating with the Win32 printing API. This class cannot be inherited.

PrintEventArgs

Provides data for the System.Drawing.Printing.PrintDocument.BeginPrint and System.Drawing.Printing.PrintDocument.EndPrint events.

PrintEventHandler

Represents the method that will handle the System.Drawing.Printing.PrintDocument.BeginPrint or System.Drawing.Printing.PrintDocument.EndPrint event of a System.Drawing.Printing.PrintDocument.

PrintingPermission

Controls access to printers. This class cannot be inherited.

PrintingPermissionAttribute

Allows declarative printing permission checks.

PrintingPermissionLevel

Specifies the type of printing that code is allowed to do.

PrintPageEventArgs

Provides data for the System.Drawing.Printing.PrintDocument.PrintPage event.

PrintPageEventHandler

Represents the method that will handle the System.Drawing.Printing.PrintDocument.PrintPage event of a System.Drawing.Printing.PrintDocument.

PrintRange

Specifies the part of the document to print.

QueryPageSettingsEventArgs

Provides data for the System.Drawing.Printing.PrintDocument.QueryPageSettings event.

QueryPageSettingsEventHandler

Represents the method that handles the System.Drawing.Printing.PrintDocument.QueryPageSettings event of a System.Drawing.Printing.PrintDocument.

StandardPrintController

Specifies a print controller that sends information to a printer.