How to: Print a Form by Using the PrintForm Component (Visual Basic)
The PrintForm component enables you to quickly print an image of a form exactly as it appears on screen without using a PrintDocument component. The following procedures show how to print a form to a printer, to a print preview window, and to an Encapsulated PostScript file.
To print a form to the default printer
In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
The PrintForm component is added to the component tray.
In the Properties window, set the PrintAction property to PrintToPrinter.
Add the following code in the appropriate event handler (for example, in the Click event handler for a PrintButton).
PrintForm1.Print()
To display a form in a print preview window
In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
The PrintForm component is added to the component tray.
In the Properties window, set the PrintAction property to PrintToPreview.
Add the following code in the appropriate event handler (for example, in the Click event handler for a PrintButton).
PrintForm1.Print()
To print a form to a file
In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.
The PrintForm component is added to the component tray.
In the Properties window, set the PrintAction property to PrintToFile.
Optionally, select the PrintFileName property and type the full path and file name for the destination file.
If you skip this step, the user will be prompted for a file name at run time.
Add the following code in the appropriate event handler (for example, in the Click event handler for a PrintButton).
PrintForm1.Print()
See Also
Tasks
How to: Print the Client Area of a Form (Visual Basic)
How to: Print Client and Non-Client Areas of a Form (Visual Basic)
How to: Print a Scrollable Form (Visual Basic)