Print Dialogs in GDI+ using VB.NET

In this article I will explain about Print Dialogs in GDI+.
  • 2917
Download Files:
 

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:

  • PrintDialog
  • PrintPriviewDialog
  • PrintPriviewControl
  • PageSetupDialog

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.

Figure2011_16.jpg

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


  Dim printDlg As New Windows.Forms.PrintDialog()

        Dim printDoc As New PrintDocument()

        printDoc.DocumentName = "Print Document"

        printDlg.Document = printDoc

        printDlg.AllowSelection = True

        printDlg.AllowSomePages = True

        'Call ShowDialog

        If printDlg.showDialog() = DialogResult.OK Then

            printDoc.Print()

        End If

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.


Conclusion

Hope the article would have helped you in understanding Print Dialogs in GDI+. Read other articles on GDI+ on the website.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.