PrintDialog in Visual Basic .NET
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This lesson describes the PrintDialog control
Visual Basic offers a wide range of dialog boxes that allow the user to make standard selections and each of them has a very specific purpose.
The purpose of the PrintDialog is printing a document.
This component displays a dialog box that lets the user prepare to print. The dialog lets the user select a printer, modify printer properties, select the pages to print, and determine the number of copies to print.
To display the dialog you call its ShowDialog method.
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then ' print the document End If
As you see some features are disabled by default, and to enable them you have to change some properties of the PrintDialog control. For example, you may want to enable AllowPrintToFile (enables the Print to file button), AllowSelection (enables the Selection radio button) and AllowSomePages (enables the Pages radio button, as well as the From and To text boxes).
Evidently most of the options were enabled:
Finally you set the control's Document property which is a PrintDocument object that provides the dialog with a PrinterSettings object.
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then PrintDocument1.Print() End IfPrevious Lesson | Next Lesson