While selecting a printer from the Printers collection is a relatively effortless task, sometimes your users need to do more than simply selecting the printer. They may need to choose a different paper size or input tray, or change any of the properties available with the Printer object. In this situation, you should use the CommonDialog control and the ShowPrinter method. This provides the standard printer selection dialog box that you see in Figure 9.1.
Figure 9.1: The Printer dialog box
The Printer dialog box offers a number of options. Users can select the range of pages to be printed and the number of copies to be created. They also can access the Printer Properties dialog box, shown in Figure 9.2, and change any of the printer’s properties, such as paper size, orientation, paper source, and graphics resolution.
Figure 9.2: The Printer Properties dialog box
It is important to realize that the CommonDialog control doesn’t talk to the printer at all. It merely collects information that your application may or may not send to the printer. Note that you also can set default values or disable some of these fields, such as the range of pages to be printed, by using the Flags property.
The block of code in Listing 9.3 shows how to use the CommonDialog control to change the system default printer to whatever the user selects. Also, two copies of the document will be printed by default, unless the user explicitly changes the number of copies.
Listing 9.3: MenuConfigure_Click Event in Printer
Private Sub MenuConfigure_Click()
CommonDialog1.Copies = 2
CommonDialog1.PrinterDefault = True
CommonDialog1.ShowPrinter
End Sub
WARNING: Setting PrinterDefault may cause problems: Any changes the user makes to the default printer in the CommonDialog control with PrinterDefault set to True will be reflected in the default Windows system printer. Since you may not want the user to be able to make changes to the default system printer, use caution when setting this property to True.