Home » VB.NET Print Dialog Box

VB.NET Print Dialog Box

by Online Tutorials Library

VB.NET Print Dialog Box

It is used to display the PrintDialog box in an application. It is an important dialog control that allows the user to select sections of a document and then select a printer to print pages from the Windows Forms application. Furthermore, a user can specify the range of pages to print, printer to use, number of copies in the PrintDialog box. And we can display the PrintDialog control in a Windows form using the ShowDialog() method.

Let’s create a PrintDialog control in the VB.NET Windows form using the following steps.

Step 1: We have to find the PrintDialog, PrintDocument, PrintPreviewDialog control from the toolbox. Drag and drop the PrintDialog, PrintDocument, PrintPreviewDialog control onto the window form, as shown below.

VB.NET Print Dialog Box

Step 2: Once the Dialog is added to the form, we can set various properties of the PrintDialog by clicking on the PrintDialog, PrintDocument, PrintPreviewDialog control.

Print Dialog Properties

There are following properties of the Print Dialog Dialog Box.

Properties Description
AllowPrintToFile The AllowPrintToFile property is used to set a value in the control box representing whether the Print to File checkbox is enabled in the dialog box.
Document The Document property is used to set a value in the dialog box representing whether the PrintDocument is capable of receiving PrintSettings.
AllowCurrentPage The AllowCurrentPage property is used to set a value representing whether the Current Page option button is displayed in the PrintDialog box.
PrintToFile The PrintToFile property is used to set or get a value in the control that represents whether the Print to File checkbox is selected in the dialog box.
ShowHelp The ShowHelp property is used to set a value that represents whether the Help button should be displayed in the dialog box.
PrinterSetting It is used to set the printer setting property in the PrintDialog box.
AllowSelection The AllowSelection property is used to set a value in the control that represents whether the Selection option button is enabled in the PrintDialog box.

Methods of Print Dialog Control

Method Description
ShowDialog() The ShowDialog () method is used to run a common dialog box with the default setting.
Reset() The Reset() method is used to reset all changes to their default values.
Dispose() The Dispose() method is used to free all resources used by the Control or component in the Dialog Box.
RunDialog() It is used to override a derived class to create a common dialog box.

Events of PrintDialog Control

Events Description
Disposed When control or component is terminated by calling the Dispose() method, a Dispose event occurs.
HelpRequest When a user clicks the Help button of the dialog box, the HelpRequest event is called.

Let’s create a simple program to print and preview the document in the VB.NET Windows Forms.

Printbox.vb

Output:

VB.NET Print Dialog Box

Write some text in the textbox. We have written the following text in the text box, as shown below.

VB.NET Print Dialog Box

After writing the text, click the Print button to print the document and set printer settings, as shown below.

VB.NET Print Dialog Box

Even we can check the preview of the document by clicking on the Print Preview button; it shows the below image.

VB.NET Print Dialog Box


You may also like