Main Page
Specifying Drawing Colors
In Visual Basic, you can specify drawing colors with the Color structure. To create a custom color, you can use the FromArgb method of this structure. There are a number of overloaded versions of the FromArgb method; one allows you to specify the red, green, and blue color values for the new color as bytes (holding values ranging from 0 to 255). For example, white has the (red, green, blue) color values (255, 255, 255), bright green is (0, 255, 0), gray is (128, 128, 128), bright blue is (0, 0, 255), and so on. Here's how I use the FromArgb method to create a bright red pen and use it to draw a line:
The Color structure also comes with dozens of built-in colors, which are the same as those used in the Pens and Brushes classes, which you can find in Table 13.6. For example, you can use such colors as Color.SteelBlue or Color.Teal, and so on.
 |
Table 13.6: Colors of the Pens and Brushes classes.
AliceBlue
|
AntiqueWhite
|
Aqua
|
Aquamarine
|
Azure
|
Beige
|
Bisque
|
Black
|
BlanchedAlmond
|
Blue
|
BlueViolet
|
Brown
|
BurlyWood
|
CadetBlue
|
Chartreuse
|
Chocolate
|
Coral
|
CornflowerBlue
|
Cornsilk
|
Crimson
|
Cyan
|
DarkBlue
|
DarkCyan
|
DarkGoldenrod
|
DarkGray
|
DarkGreen
|
DarkKhaki
|
DarkMagenta
|
DarkOliveGreen
|
DarkOrange
|
DarkOrchid
|
DarkRed
|
DarkSalmon
|
DarkSeaGreen
|
DarkSlateBlue
|
DarkSlateGray
|
DarkTurquoise
|
DarkViolet
|
DeepPink
|
DeepSkyBlue
|
DimGray
|
DodgerBlue
|
Firebrick
|
FloralWhite
|
ForestGreen
|
Fuchsia
|
Gainsboro
|
GhostWhite
|
Gold
|
Goldenrod
|
Gray
|
Green
|
GreenYellow
|
Honeydew
|
HotPink
|
IndianRed
|
Indigo
|
Ivory
|
Khaki
|
Lavender
|
LavenderBlush
|
LawnGreen
|
LemonChiffon
|
LightBlue
|
LightCoral
|
LightCyan
|
LightGoldenrodYellow
|
LightGray
|
LightGreen
|
LightPink
|
LightSalmon
|
LightSeaGreen
|
LightSkyBlue
|
LightSlateGray
|
LightSteelBlue
|
LightYellow
|
Lime
|
LimeGreen
|
Linen
|
Magenta
|
Maroon
|
MediumAquamarine
|
MediumBlue
|
MediumOrchid
|
MediumPurple
|
MediumSeaGreen
|
MediumSlateBlue
|
MediumSpringGreen
|
MediumTurquoise
|
MediumVioletRed
|
MidnightBlue
|
MintCream
|
MistyRose
|
Moccasin
|
NavajoWhite
|
Navy
|
OldLace
|
Olive
|
OliveDrab
|
Orange
|
OrangeRed
|
Orchid
|
PaleGoldenrod
|
PaleGreen
|
PaleTurquoise
|
PaleVioletRed
|
PapayaWhip
|
PeachPuff
|
Peru
|
Pink
|
Plum
|
PowderBlue
|
Purple
|
Red
|
RosyBrown
|
RoyalBlue
|
SaddleBrown
|
Salmon
|
SandyBrown
|
SeaGreen
|
SeaShell
|
Sienna
|
Silver
|
SkyBlue
|
SlateBlue
|
SlateGray
|
Snow
|
SpringGreen
|
SteelBlue
|
Tan
|
Teal
|
Thistle
|
Tomato
|
Transparent
|
Turquoise
|
Violet
|
Wheat
|
White
|
WhiteSmoke
|
Yellow
|
YellowGreen
| | | |
 |
| Tip |
You can recover the red, green, and blue values for a color using the Color structure's R, G, and B members (these members are read-only).
|