View contents of this chapter

The Color Dialog Box

The Color dialog box allows the user to select a color from a palette or to create and select a custom color. At run time, when the user chooses a color and closes the dialog box, you use the Color property to get the selected color. To turn a Common Dialog Box control into the Color selection dialog box and display the color selection dialog box, follow these steps:

Baby Steps

  • Set the Common Dialog Box control's DialogTitle property to the title you want to appear in the Color selection's title bar, such as "Select a background color".
  • Set the control's Flags property.
  • Call the ShowColor method.

The following table shows the common Flag values:

Literal Flags
cdlCCFullOpen &H2 Entire dialog box is displayed, including the Define Custom Colors section
cdlCCShowHelp &H8 Causes the dialog box to display a Help button
cdlCCPreventFullOpen &H4 Disables the Define Custom Colors command button and prevents the user from defining custom colors
cdlCCRGBInit &H1 Sets the initial color value for the dialog box

Play Sound You can combine one or more FLAGS property values to set up the Color Dialog box.

Suppose you want to display the Color selection box and let the user select a custom color. The following code shows how to produce a color dialog box:

dlgColor.Flags = cdlCCPreventFullOpen 'Display complete Color DB

The following figure shows the dialog box

Figure 16.3

When the user closes the dialog box, the dialog box's properties are set according to the user's selection. The most important property is the Color property, which holds the hexadecimal value of the color the user selected. You could write the following code to change the form's background color:

frmDemo.BackColor = dlgColor.Color

© Universal Teacher Publications        INDEX Previous Screen Next Screen