The common dialog control provides a standard set of dialog boxes for operations such as opening and saving files, setting print options, and selecting colors and fonts. The control also has the ability to display Help by running the Windows Help engine.
Figure 7.11 The common dialog control
The common dialog control provides an interface between Visual Basic and the procedures in the Microsoft Windows dynamic-link library Commdlg.dll. To create a dialog box using this control, Commdlg.dll must be in your Microsoft Windows \System directory.
You use the common dialog control in your application by adding it to a form and setting its properties. The dialog displayed by the control is determined by the methods of the control. At run time, a dialog box is displayed or the Help engine is executed when the appropriate method is invoked; at design time, the common dialog control is displayed as an icon on a form. This icon can't be sized.
The common dialog control allows you to display these commonly used dialog boxes:
- Open
- Save As
- Color
- Font
To use the common dialog control
- If you haven't already done so, add the common dialog control to the toolbox by selecting Components from the Project menu. Locate and select the control in the Controls tabbed dialog, then click the OK button.
- On the toolbox, click the CommonDialog control and draw it on a form.When you draw a common dialog control on a form, it automatically resizes itself. Like the timer control, the common dialog control is invisible at run time.
- At run time, use the appropriate method, as listed in the following table, to display the desired dialog.
Method Dialog displayed ShowOpen Open ShowSave Save As ShowColor Color ShowFont Font ShowPrinter Print ShowHelp Invokes Windows Help