Chapter 17 Working with Printers 431
Two additional printing controls are available on the Printing tab of the Toolbox, and they
work much like the familiar PrintDialog and OpenFileDialog controls that you’ve used in this
book:
n The PrintPreviewDialog control displays a custom Print Preview dialog box.
n The PageSetupDialog control displays a custom Page Setup dialog box.
As with other dialog boxes, you can add these printing controls to your form by using the
Toolbox, or you can create them programmatically.
In the following exercise, you’ll add Print Preview and Page Setup dialog boxes to the Print
File program you’ve been working with. In the completed practice files, I’ve named this
project Print Dialogs so that you can distinguish the code of the two projects, but you can
add the dialog box features directly to the Print File project if you want.
Add PrintPreviewDialog and PageSetupDialog controls
- If you didn’t complete the previous exercise, open the Print File project from the
C:\Vb10sbs\Chap17\Print File folder.
The Print File project is the starting point for this project. - Display the form, and then use the Button control to add two additional buttons to the
top of the form. - Double-click the PrintPreviewDialog control on the Printing tab of the Toolbox.
A print preview dialog object is added to the component tray.
- Double-click the PageSetupDialog control on the Printing tab of the Toolbox.
A page setup dialog object is added to the component tray. If the objects in the
component tray obscure one another, you can drag them to a better (more visible)
location, or you can right-click the component tray and select Line Up Icons.
- Set the following properties for the button objects on the form:
Object Property Setting
Button1 Name
Enabled
Text
btnSetup
False
“Page Setup”
Button2 Name
Enabled
Text
btnPreview
False
“Print Preview”