- VB.Net Basic Tutorial
- VB.Net - Home
- VB.Net - Overview
- VB.Net - Environment Setup
- VB.Net - Program Structure
- VB.Net - Basic Syntax
- VB.Net - Data Types
- VB.Net - Variables
- VB.Net - Constants
- VB.Net - Modifiers
- VB.Net - Statements
- VB.Net - Directives
- VB.Net - Operators
- VB.Net - Decision Making
- VB.Net - Loops
- VB.Net - Strings
- VB.Net - Date & Time
- VB.Net - Arrays
- VB.Net - Collections
- VB.Net - Functions
- VB.Net - Subs
- VB.Net - Classes & Objects
- VB.Net - Exception Handling
- VB.Net - File Handling
- VB.Net - Basic Controls
- VB.Net - Dialog Boxes
- VB.Net - Advanced Forms
- VB.Net - Event Handling
- VB.Net Advanced Tutorial
- VB.Net - Regular Expressions
- VB.Net - Database Access
- VB.Net - Excel Sheet
- VB.Net - Send Email
- VB.Net - XML Processing
- VB.Net - Web Programming
- VB.Net Useful Resources
- VB.Net - Quick Guide
- VB.Net - Useful Resources
- VB.Net - Discussion
VB.Net - PrintDialog Control
The PrintDialog control lets the user to print documents by selecting a printer and choosing which sections of the document to print from a Windows Forms application.
There are various other controls related to printing of documents. Let us have a brief look at these controls and their purpose. These other controls are −
The PrintDocument control − it provides support for actual events and operations of printing in Visual Basic and sets the properties for printing.
The PrinterSettings control − it is used to configure how a document is printed by specifying the printer.
The PageSetUpDialog control − it allows the user to specify page-related print settings including page orientation, paper size and margin size.
The PrintPreviewControl control − it represents the raw preview part of print previewing from a Windows Forms application, without any dialog boxes or buttons.
The PrintPreviewDialog control − it represents a dialog box form that contains a PrintPreviewControl for printing from a Windows Forms application.
Following is the Print dialog box −
Properties of the PrintDialog Control
The following are some of the commonly used properties of the PrintDialog control −
Sr.No. | Property & 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. |
Methods of the PrintDialog Control
The following are some of the commonly used methods of the PrintDialog control −
Sr.No. | Method Name & Description |
---|---|
1 |
Reset Resets all options to their default values. |
2 |
RunDialog When overridden in a derived class, specifies a common dialog box. |
3 |
ShowDialog Runs a common dialog box with a default owner. |
Example
In this example, let us see how to show a Print dialog box in a form. Take the following steps −
Add a PrintDocument control, a PrintDialog control and a Button control on the form. The PrintDocument and the PrintDialog controls are found on the Print category of the controls toolbox.
Change the text of the button to 'Print'.
Double-click the Print button and modify the code of the Click event as shown −
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click PrintDialog1.Document = PrintDocument1 PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings PrintDialog1.AllowSomePages = True If PrintDialog1.ShowDialog = DialogResult.OK Then PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings PrintDocument1.Print() End If End Sub
When the application is compiled and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window −
Click the Print button to make the Print dialog box appear.