O'Reilly logo

C# 5.0 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required