JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

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:

            Dim c As Color = Color.FromArgb(255, 0, 0)
            Dim RedPen As New Pen(c)
            g.DrawLine(RedPen, point1, point2)

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).

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor