Chapter 4 Working with Menus, Toolbars, and Dialog Boxes 111
Control Purpose
PrintDialog Lets the user set printing options
PrintPreviewDialog Displays a print preview dialog box as the Word program does
PageSetupDialog Lets the user control page setup options, such as margins, paper size,
and layout
In the following exercises, you’ll practice using the OpenFileDialog and ColorDialog controls.
The OpenFileDialog control lets your program open bitmap files, and the ColorDialog
control enables your program to change the color of the clock output. You’ll connect these
dialog boxes to the toolbar that you just created, although you could just as easily connect
them to menu commands.
Add OpenFileDialog and ColorDialog controls
- Click the OpenFileDialog control on the Dialogs tab of the Toolbox, and then click
the form.
An open file dialog box object appears in the component tray. - Click the ColorDialog control on the Dialogs tab of the Toolbox, and then click the
form again.
The component tray now looks like this:
Just like the menu strip and tool strip objects, the open file dialog box and color dialog
box objects appear in the component tray, and they can be customized with property
settings.
Now you’ll create a picture box object by using the PictureBox control. As you’ve seen, the
picture box object displays artwork on a form. This time, you’ll display artwork in the picture
box by using the open file dialog box object.
Add a picture box object
- Click the PictureBox control in the Toolbox.
- Draw a large, square picture box object on the form, below the label.
- Use the smart tag in the picture box object to set the SizeMode property of the picture
box to StretchImage.
Now you’ll create event procedures for the Color and Open buttons on the toolbar.