Having both screen and printer output generated through identical GDI+ commands means that I can make this a really short chapter, referring you back to Chapter 18 for details. But it also means that there needs to be a canvas—a
System.Drawing.Graphics object—where the printer-specific GDI+ commands target their output. The
System.Drawing.Printing.PrintDocument class provides you with the output canvas you need for both ordinary printing and "print preview" output. There are three ways to use the
PrintDocument control to a form from the Windows Forms toolbox. This control appears by default in the toolbox's Printing section. Assign its properties and respond to its events as with any other control.
Create a field-level instance of the
PrintDocument class. Include the
With Events clause in the definition to get event management.
Create a local instance of
PrintDocument, and connect any events using
These are standard methods in .NET, but having a control variation makes the class that much more convenient. We'll get into the actual printing code a little later.
Four other printer-specific controls are available for Windows Forms projects:
This control presents a standard Windows printer settings dialog that lets the user configure a specific print job, or all print jobs for the application. The control's
ShowDialog method displays the form shown in Figure 20-2. The control also exposes properties related to the user's ...