It is an important dialog control that lets the user choose sections of a document and then choose a printer to print pages from a Windows Forms application.
In VB.net Print Dialog Box, a user can also specify the range of pages to print, the printer to use, and the number of copies to print.
And we can show the PrintDialog control in a Windows form by using the ShowDialog() method.
What is a Print Dialog Box in VB.net?
A Print Dialog in VB.net is used to open up the Windows Print Dialog.
A typical Open File dialog, where you can choose a printer from the list of available printers, set printer properties, set print range, number of pages, number of copies, and so on.
Clicking the OK button sends the document to the printer.
Print Dialog Properties in VB.net
The Print Dialog Box in VB.net has the following Properties:
| # | Print Dialog Properties in VB.net | Description |
|---|---|---|
| 1. | AllowCurrentPage | Gets or sets a value indicating whether the Current Page option button is displayed. |
| 2. | AllowPrintToFile | Gets or sets a value indicating whether the Print to file check box is enabled. |
| 3. | AllowSelection | Gets or sets a value indicating whether the Selection option button is enabled. |
| 4. | AllowSomePages | Gets or sets a value indicating whether the Pages option button is enabled. |
| 5. | Document | Gets or sets a value indicating the PrintDocument used to obtain PrinterSettings. |
| 6. | PrinterSettings | Gets or sets the printer settings the dialog box modifies. |
| 7. | PrintToFile | Gets or sets a value indicating whether the Print to file check box is selected. |
| 8. | ShowHelp | Gets or sets a value indicating whether the Help button is displayed. |
| 9. | ShowNetwork | Gets or sets a value indicating whether the Network button is displayed. |
Print Dialog Methods in VB.net
The Print Dialog Box in VB.net has the following Methods:
| # | Print Dialog Methods in VB.net | Description |
|---|---|---|
| 1. | ShowDialog() | The ShowDialog () method is used to run a common dialog box with the default setting. |
| 2. | Reset() | The Reset() method is used to reset all changes to their default values. |
| 3. | Dispose() | The Dispose() method is used to free all resources used by the Control or component in the Dialog Box. |
| 4. | RunDialog() | It is used to override a derived class to create a common dialog box. |
Print Dialog Events in VB.net
The Print Dialog Box in VB.net has the following Events:
| # | Print Dialog Events in VB.net | Description |
|---|---|---|
| 1. | Disposed | When control or component is terminated by calling the Dispose() method, a Dispose event occurs. |
| 2. | HelpRequest | When a user clicks the Help button of the dialog box, the HelpRequest event is called. |
Let’s make a simple program in VB.NET Windows Forms that lets us print and look at the document before we print it.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PrintPreviewDialog1.Document = PrintDocument1
End Sub
Private Sub Button1_Click_4(sender As Object, e As EventArgs) Handles Button1.Click
If RichTextBox1.Text = " " Then
MsgBox("Please write some text...")
Else
PrintPreviewDialog1.ShowDialog()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If PrintDialog1.ShowDialog = DialogResult.OK Then 'Open the print dialog box
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print() 'print a document
End If
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim font As New Font("Times New Roman", 24, FontStyle.Bold) 'set the font to display
e.Graphics.DrawString(RichTextBox1.Text, font, Brushes.Blue, 100, 100) 'The DrawString() function is used to print letters.
End Sub
End Class
Program Output:
Write something in the textbox. As shown below, we wrote the following text in the text box.
After you write the text, click the Print button to print the document and set the printer settings, as shown below.
We can also see a preview of the document by clicking the Preview button, which brings up the image below.
Summary
A PrintDialog control lets users open the Windows Open File Dialog and select a file to print.
In this article, we went over how to use a Windows Open File Dialog using Microsoft Visual Studio and set its Properties, Methods, and Events in a Windows Forms application.
PREVIOUS
NEXT
Common use cases for Print Dialog Box
Print Dialog Box appears in most Windows Forms applications. Typical scenarios:
- File save operations. Prompt users to pick a target file name and format before writing data.
- File open operations. Let users browse for spreadsheets, images, PDFs, or configuration files to import.
- Font selection. Give users control over typography in rich-text editors, report designers, or accessibility settings.
- Color selection. Used in drawing apps, chart configurators, and theme editors.
- Print previews. Route content to the printer with pagination and margins under user control.
Best practices when using Print Dialog Box
- Always set a default. Users expect a sensible starting value (e.g., the last used color or the current font).
- Handle DialogResult. Check whether the user clicked OK vs Cancel before applying changes.
- Set filters correctly. For file dialogs, restrict extensions to the ones your app actually reads.
- Wrap in Using blocks. Dialog objects hold OS resources; Using ensures cleanup.
- Test on high-DPI monitors. Dialogs render differently at 125% and 150% scaling.
Working code example
Full working example showing Print Dialog Box in a real Windows Forms context:
Private Sub btnPick_Click(sender As Object, e As EventArgs) Handles btnPick.Click
Using dlg As New OpenFileDialog()
dlg.Title = "Select a file"
dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If dlg.ShowDialog() = DialogResult.OK Then
Dim contents As String = System.IO.File.ReadAllText(dlg.FileName)
txtOutput.Text = contents
End If
End Using
End Sub
Troubleshooting common issues with Print Dialog Box
- Dialog does not appear. Confirm ShowDialog() is called on the UI thread. Cross-thread invocations must marshal via Control.Invoke().
- File permission errors. Wrap file operations in Try/Catch. UAC-protected folders throw UnauthorizedAccessException.
- Filter string ignored. Filters use the exact “Description|*.ext|Description2|*.ext2” format. A single stray character breaks parsing silently.
- Font not applied. After dialog closes, assign dlg.Font to the target control’s Font property explicitly.
- Print job silently drops. Confirm PrinterSettings.IsValid before calling Print().






