The Color Selection Dialog allows the user to choose a specific color value. The user can generate a color value by modifying the RGB or hue, saturation, luminosity (HSL) color values of the dialog box user interface. The Color Selection Dialog box returns the RGB value of the color selected by the user.
If the user clicks the OK button, the old color is replaced by the new one selected by the user.
If the user cancels the Color Selection Dialog box or an error occurs no modification is done.
RGB Color Model #
The RGB model is used to designate colors for displays and other devices that emit light. Valid red, green, and blue values range from 0 through 255, with 0 indicating minimum intensity and 255 indicating maximum intensity. The following illustration shows how the primary colors red, green, and blue can be combined to produce four additional colors. (For display devices, the color black results when the red, green, and blue values are set to 0. In display technology, black is the absence of all colors.)
The following table lists eight colors of the RGB model and their associated RGB values.
Color | RGB values |
Red | 255, 0, 0 |
Green | 0, 255, 0 |
Blue | 0, 0, 255 |
Cyan | 0, 255, 255 |
Magenta | 255, 0, 255 |
Yellow | 255, 255, 0 |
White | 255, 255, 255 |
Black | 0, 0, 0 |
HSL Color Model #
The Color Selection Dialog box provides controls for specifying HSL values. The following illustration shows the color spectrum control and the luminosity slide control that appear in the Color Selection Dialog box. The illustration also shows the ranges of values the user can specify with these controls.
In the Color Selection Dialog box, the saturation and luminosity values must be in the range 0 through 240, and the hue value must be in the range 0 through 239.
Converting HSL Values to RGB Values #
The dialog box procedure provided in the Color Selection Dialog box contains code that converts HSL values to the corresponding RGB values. The following table lists eight colors of the RGB model and their associated HSL and RGB values.
Color | HSL values | RGB values |
Red | 0, 240, 120 | 255, 0, 0 |
Green | 40, 240, 120 | 0, 255, 0 |
Blue | 80, 240, 120 | 0, 0, 255 |
Cyan | 120, 240, 120 | 0, 255, 255 |
Magenta | 160, 240, 120 | 255, 0, 255 |
Yellow | 200, 240, 120 | 255, 255, 0 |
White | 0, 0, 240 | 255, 255, 255 |
Black | 0, 0, 0 | 0, 0, 0 |