Print Dialogs in GDI+
In this article I will explain about Print Dialogs in GDI+.
This article has been excerpted from book "Graphics Programming with GDI+".
In the beginning of this article we said that all printing functionality is defined in the System.Drawing.Printing namespace. That statement is not entirely true. Actually, a few printing-related classes are defined in the System.Windows.Forms namespace. These classes are:
These classes are also available as Windows Forms controls in Visual Studio .NET; we can add them to a form by dragging the control from the toolbox. The toolbox with the three print dialogs is shown in Figure 11.16.
However, adding and using these controls programmatically is even easier than using the toolbox, as we will soon see. Before you learn how to use them, let's explore their functionality.
FIGURE 11.16: Print dialogs in the Visual Studio .NET toolbox
The PrintDialog Control
The PrintDialog class represents the PrintDialog control in the .NET Framework library. This class represents a standard Windows printer dialog, which allows the user to select a printer and choose which portions of the document to print. Table 11.7 describes the PrintDialog class properties. By default, all of these properties are false when a PrintDialog object is created, and all the properties have both get and set options.
Beside the properties defined in Table 11.7, PrintDialog has on method called Reset. This method resets all options, the last selected printer, and the page settings to their default values.
Listing 11.28 creates a PrintDialog object, sets it properties, calls ShowDialog and prints the document.
LISTING 11.28: Create and using the PrintDialog control
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = "Print Document";
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
if (printDlg.showDialog() == DialogResult.OK)
TABLE 11.7: PrintDialog properties
Indicates whether the From To Page option button is enabled.
Indicates whether the Pages option button is enabled.
Identifies the PrintDocument object used to obtain printer settings.
Identifies the printer settings that the dialog box modifies.
Indicates whether the Print to file check box is checked.
Indicates whether the Help button is displayed.
Indicates whether the Network button is displayed.
Hope the article would have helped you in understanding Print Dialogs in GDI+. Read other articles on GDI+ on the website.
| ||This book teaches .NET developers how to work with GDI+ as they develop applications that include graphics, or that interact with monitors or printers. It begins by explaining the difference between GDI and GDI+, and covering the basic concepts of graphics programming in Windows.|