The System.Drawing.Printing namespace provides print-related services for Windows Forms applications.
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. Calling the PrintDocument..::.Print method raises the PrintDocument..::.PrintPage event, which should be handled to perform the document layout for printing.
Use the Graphics property of the PrintPageEventArgs object obtained from the PrintDocument..::.PrintPage event to specify the output to print. 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. For more information about this process, see the Graphics and StreamReader classes. You can view an example of printing a text document in the PrintDocument class overview topic.
When implemented in a derived class, the PrintController controls how a PrintDocument is printed. 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. For more information about printing dialog boxes, see PrintDialog and 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 PreviewPrintController, PrintPreviewDialog, and PrintPreviewControl.
Caution: |
|---|
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.
Reference
Other Resources