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 toolboxThe PrintDialog ControlThe 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; //Call ShowDialog if (printDlg.showDialog() == DialogResult.OK) printDoc.Print();TABLE 11.7: PrintDialog properties
Property
Description
AllowSelection
Indicates whether the From To Page option button is enabled.
AllowSomePages
Indicates whether the Pages option button is enabled.
Document
Identifies the PrintDocument object used to obtain printer settings.
PrinterSettings
Identifies the printer settings that the dialog box modifies.
PrintToFile
Indicates whether the Print to file check box is checked.
ShowHelp
Indicates whether the Help button is displayed.
ShowNetwork
Indicates whether the Network button is displayed.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: