Share via


Visual Basic Concepts

Working with Color

Visual Basic uses a consistent system for all color properties and graphics methods. A color is represented by a Long integer, and this value has the same meaning in all contexts that specify a color.

Specifying Colors at Run Time

There are four ways to specify a color value at run time:

  • Use the RGB function.

  • Use the QBColor function to choose one of 16 Microsoft QuickBasic® colors.

  • Use one of the intrinsic constants listed in the Object Browser.

  • Enter a color value directly.

This section discusses how to use the RGB and QBColor functions as simple ways to specify color. See "Using Color Properties" later in this chapter for information on using constants to define color or directly entering color values.

Using the RGB Function

You can use the RGB function to specify any color.

To use the RGB function to specify a color

  1. Assign each of the three primary colors (red, green, and blue) a number from 0 to 255, with 0 denoting the least intensity and 255 the greatest.

  2. Give these three numbers as input to the RGB function, using the order red-green-blue.

  3. Assign the result to the color property or color argument.

Every visible color can be produced by combining one or more of the three primary colors. For example:

' Set background to green.
Form1.BackColor = RGB(0, 128, 0)
' Set background to yellow.
Form2.BackColor = RGB(255, 255, 0)
' Set point to dark blue.
PSet (100, 100), RGB(0, 0, 64)

For More Information   For information on the RGB function, see "RGB Function" in the Language Reference.