Chapter 4 Working with Menus, Toolbars, and Dialog Boxes 113
o Joint Photographic Experts Group (JPEG) format ( .jpg and .jpeg files)
o Portable Network Graphics (PNG) format ( .png files)
o Graphics Interchange Format ( .gif files)
To add additional items to the Filter list, you can type a pipe symbol (|) between items.
For example, this program statement
OpenFileDialog1.Filter = "Bitmaps (*.bmp)|*.bmp|Metafiles (*.wmf)|*.wmf"
allows both bitmaps and Windows metafiles to be chosen in the Open dialog box.
The second statement in the event procedure displays the Open dialog box in
the program. The ShowDialog method returns a result named DialogResult, which
indicates the button on the dialog box that the user clicked. To determine whether
the user clicked the Open button, an If... Then decision structure is used to check
whether the returned result equals DialogResult.OK. If it does, a valid .bmp file path
should be stored in the FileName property of the open file dialog box object. (You’ll
learn more about the syntax of If... Then decision structures in Chapter 6, “Using
Decision Structures .”)
The third statement uses the file name selected in the dialog box by the user. When
the user selects a drive, folder, and file name and then clicks Open, the complete path
is passed to the program through the OpenFileDialog1.FileName property. The System.
Drawing.Image.FromFile method, which loads electronic artwork, is then used to copy
the specified Windows bitmap into the picture box object. (I wrapped this statement
with the line continuation character (_) because it was rather long .)
Now you’ll write an event procedure for the Color button that you added to the toolbar.
Write the Color button event procedure
- Display the form again, and then double-click the Color button on the toolbar that
you added to the form.
An event procedure named ToolStripButton1_Click appears in the Code Editor. The
object name includes Button1 because it was the first nonstandard button that
you added to the toolbar. (You can change the name of this object to something
more intuitive, such as ColorToolStripButton, by clicking the button on the form
and changing the Name property in the Properties window .) - Type the following program statements in the event procedure:
ColorDialog1.ShowDialog()
Label1.ForeColor = ColorDialog1.Color
The first program statement uses the ShowDialog method to open the color dialog
box. As you learned earlier in this chapter, ShowDialog is the method you use to open