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.

  1. Create a PrintDocument object either at design time or at run time.
  2. Start the printing process by doing one of the following:
    1. To send a printout to a printer, call the PrintDocument object’s Print method.
    2. To display a print preview in a PrintPreviewDialog:
      1. Create a PrintPreviewDialog object either at design time or at run time.
      2. Set the object’s Document property equal to the PrintDocument object you created in Step 1.
      3. Call the dialog’s ShowDialog method to display it.
    3. To display a print preview in a PrintPreviewControl:
      1. Create a PrintPreviewControl object either at design time or at run time.
      2. Set the object’s Document property equal to the PrintDocument object you created in Step 1.
  3. 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.