Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

114 Part I Getting Started with Microsoft Visual Basic 2010


any form as a dialog box, including a form created by one of the standard dialog box
controls that Visual Studio provides. The second statement in the event procedure
assigns the color that the user selected in the dialog box to the ForeColor property of
the Label1 object. You might remember Label1 from earlier in this chapter—it’s the
label box you used to display the current time and date on the form. You’ll use the
color returned from the color dialog box to set the color of the text in the label.
Note that the color dialog box can be used to set the color of any UI element that
supports color. Other possibilities include the background color of the form, the colors
of shapes on the form, and the foreground and background colors of objects.


  1. Click the Save All button on the Standard toolbar to save your changes.


Controlling Color Choices by Setting Color Dialog Box Properties
If you want to further customize the color dialog box, you can control what color
choices the dialog box presents to the user when the dialog box opens. You can adjust
these color settings by selecting the ColorDialog1 object and using the Properties
window, or by setting properties by using program code before you display the dialog
box with the ShowDialog method. Table 4-3 describes the most useful properties of
the ColorDialog control. Each property should be set with a value of True to enable the
option or False to disable the option.

TABLE 4-3 ColorDialog Control Properties
Property Meaning
AllowFullOpen Set to True to enable the Define Custom Colors button in the
dialog box.
AnyColor Set to True if the user can select any color shown in the dialog box.
FullOpen Set to True if you want to display the Custom Colors area when the
dialog box first opens.
ShowHelp Set to True if you want to enable the Help button in the dialog box.
SolidColorOnly Set to True if you want the user to select only solid colors (dithered
colors—those that are made up of pixels of different colors—are
disabled).

Now you’ll run the Menu program and experiment with the menus and dialog boxes you’ve
created.

Run the Menu program

Tip The complete Menu program is located in the C:\Vb10sbs\Chap04\Menu folder.
Free download pdf