Appendix N Printing and Graphics
This appendix provides information about printing and the graphics classes used by Windows Forms applications. Printing is different in Windows Forms and WPF applications. The next sections explain how to print in a Windows Forms application. The sections after that explain how to print in a WPF application.
Windows Forms Printing
The following section explains the basic printing process in a Windows Forms application. The section after that summarizes graphics classes and methods used to print in that kind of application.
Printing Steps
The following steps summarize how to print in a Windows Forms application.
- Create a
PrintDocument
object either at design time or at run time. - Start the printing process by doing one of the following:
- To send a printout to a printer, call the
PrintDocument
object’sPrint
method. - To display a print preview in a
PrintPreviewDialog
:- Create a
PrintPreviewDialog
object either at design time or at run time. - Set the object’s
Document
property equal to thePrintDocument
object you created in Step 1. - Call the dialog’s
ShowDialog
method to display it.
- Create a
- To display a print preview in a
PrintPreviewControl
:- Create a
PrintPreviewControl
object either at design time or at run time. - Set the object’s
Document
property equal to thePrintDocument
object you created in Step 1.
- Create a
- To send a printout to a printer, call the
- Catch the
PrintDocument
object’s events to generate the printout.
The following list summarizes the events raised by the PrintDocument
object.
Get C# 5.0 Programmer's Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.