Print Dialog Box in VB.net – Properties, Methods and Events

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.netDescription
1.AllowCurrentPageGets or sets a value indicating whether the Current Page option button is displayed.
2.AllowPrintToFileGets or sets a value indicating whether the Print to file check box is enabled.
3.AllowSelectionGets or sets a value indicating whether the Selection option button is enabled.
4.AllowSomePagesGets or sets a value indicating whether the Pages option button is enabled.
5.DocumentGets or sets a value indicating the PrintDocument used to obtain PrinterSettings.
6.PrinterSettingsGets or sets the printer settings the dialog box modifies.
7.PrintToFileGets or sets a value indicating whether the Print to file check box is selected.
8.ShowHelpGets or sets a value indicating whether the Help button is displayed.
9.ShowNetworkGets or sets a value indicating whether the Network button is displayed.
Properties and Description of Print Dialog Box in VB.net

Print Dialog Methods in VB.net

The Print Dialog Box in VB.net has the following Methods:

#Print Dialog Methods in VB.netDescription
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.
Methods and Description of Print Dialog Box in VB.net

Print Dialog Events in VB.net

The Print Dialog Box in VB.net has the following Events:

#Print Dialog Events in VB.netDescription
1.DisposedWhen control or component is terminated by calling the Dispose() method, a Dispose event occurs.
2.HelpRequestWhen a user clicks the Help button of the dialog box, the HelpRequest event is called.
Events and Descriptions of Print Dialog Box in VB.net

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:

Print Dialog Box in VB.net Output
Print Dialog Box in VB.net Output

Write something in the textbox. As shown below, we wrote the following text in the text box.

Print Dialog Box in VB.net Insert Text
Print Dialog Box in VB.net Insert Text

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

Print Dialog Box in VB.net Settings
Print Dialog Box Settings

We can also see a preview of the document by clicking the Preview button, which brings up the image below.

Print Dialog Box in VB.net Preview Text
Print Dialog Box Preview Text

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.


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().

Frequently Asked Questions

What is the Print Dialog Box in VB.NET?
The Print Dialog Box in VB.NET is a modal Windows Forms dialog that lets users pick a value (file, font, color, or printer setting) without writing custom UI code. It ships with the .NET Framework in the System.Windows.Forms namespace.
How do I show the Print Dialog Box in code?
Create an instance, set its default properties, and call ShowDialog(). Wrap it in a Using block so system resources are released even if the user closes the dialog with the X button.
How do I know if the user clicked OK on the Print Dialog Box?
ShowDialog() returns a DialogResult enumeration. Compare against DialogResult.OK before reading the dialog’s property values, otherwise you may end up processing an unpicked or default value.
Why does the Print Dialog Box appear behind my form?
Pass Me (the current form) as the owner argument: dlg.ShowDialog(Me). Without an owner, the dialog can appear behind other windows or be misplaced across multi-monitor setups.
Can I customize the Print Dialog Box appearance?
The built-in dialogs are OS-provided and only offer limited customization through their properties. For deeper styling you must write a custom form that mimics the dialog behavior.
Angel Jude Suarez


Full-Stack Developer at PIES IT Solution

Focuses on Python development, machine learning, and AI integration. Has built production AI systems including OpenAI Whisper integration for medical transcription and GPT-4o-powered diagnosis assistance. Strong background in pandas, scikit-learn, and TensorFlow.

Expertise: Python · PHP · Java · VB.NET · ASP.NET · Machine Learning · AI Integration · OpenCV · Django · CodeIgniter
 · View all posts by Angel Jude Suarez →

Leave a Comment