Print Dialogs in GDI+ using VB.NET

In this article I will explain about Print Dialogs in GDI+.
  • 2943

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.


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


        End If

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.


More Articles

© 2020 DotNetHeaven. All rights reserved.