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.
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.
||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.
||The Document property is used to set a value in the dialog box representing whether the PrintDocument is capable of receiving PrintSettings.
||The AllowCurrentPage property is used to set a value representing whether the Current Page option button is displayed in the PrintDialog box.
||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.
||The ShowHelp property is used to set a value that represents whether the Help button should be displayed in the dialog box.
||It is used to set the printer setting property in the PrintDialog box.
||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
||The ShowDialog () method is used to run a common dialog box with the default setting.
||The Reset() method is used to reset all changes to their default values.
||The Dispose() method is used to free all resources used by the Control or component in the Dialog Box.
||It is used to override a derived class to create a common dialog box.
Events of PrintDialog Control
||When control or component is terminated by calling the Dispose() method, a Dispose event occurs.
||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.
Write some text in the textbox. We have written the following text in the text box, as shown below.
After writing the text, click the Print button to print the document and set printer settings, as shown below.
Even we can check the preview of the document by clicking on the Print Preview button; it shows the below image.