Export (0) Print
Expand All

Color Handling for Visual Basic 6.0 Users

This topic compares color handling in Visual Basic 6.0 with equivalents in Visual Basic 2008.

Working with colors in Visual Basic 2008 is similar to working with colors in Visual Basic 6.0; however, there are a few conceptual differences that you need to know. In addition, the constants used to specify colors in Visual Basic 6.0 are replaced by new color enumerations in Visual Basic 2008.

In Visual Basic 6.0, colors were represented by a value of type Long; in Visual Basic 2008 colors are of type Color. In Visual Basic 6.0, constants were provided for eight standard colors; in Visual Basic 2008 there are more than 100 named colors.

TipTip:

To find an equivalent value for a Visual Basic 6.0 color that is not a standard color, you can use the ColorTranslator class and pass it the Long value of the Visual Basic 6.0 color.

Color Constants

In Visual Basic 6.0, constants were provided for system colors that could be used to map a color to the user's system preferences. In Visual Basic 2008, the system colors are of type SystemColors.

BackColor and ForeColor Properties

In Visual Basic 6.0, the BackColor and ForeColor properties of a control had to be explicitly set at design time or at run time; colors could not be inherited. In Visual Basic 2008, unless a color is explicitly set at design time or at run time, it will inherit the color setting of its parent. For more information, see Color Behavior for Visual Basic 6.0 Users.

Palette and PaletteMode Properties

In Visual Basic 6.0, the Palette and PaletteMode properties of a form were used to control the set of colors to be used when displaying images on a 256-color display. Visual Basic 2008 does not support the Palette or PaletteMode properties. For more information, see Palettes for Visual Basic 6.0 Users.

MaskColor Property

The Visual Basic 6.0 MaskColor property no longer exists for the CheckBox, Button, and RadioButton controls. You can emulate the MaskColor property by using the graphics methods. For more information, see MaskColor for Visual Basic 6.0 Users.

The following examples illustrate the differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.

Code Changes for Setting a Color to a System Color

The following code sets the BackColor of a form to match the user-selected color for the active title bar.

' Visual Basic 6.0

Me.BackColor = vbActiveTitleBar

' Visual Basic
Me.BackColor = System.Drawing.SystemColors.ActiveCaption


Code Changes for Setting a Color to a Visual Basic 6.0 Value

The following example sets the BackColor property of a TextBox control to match the lightest green (&H00C0FFC0) from the Visual Basic 6.0 color picker.

' Visual Basic 6.0

textBox1.Text = &H00C0FFC0

' Visual Basic
TextBox1.BackColor = System.Drawing.ColorTranslator.FromOle(&HC0FFC0)


The following tables list Visual Basic 6.0 constants and their Visual Basic 2008 equivalents.

Color Constant Equivalents

Visual Basic 6.0

Visual Basic 2005 Equivalent

vbBlack

Black

vbRed

Red

vbGreen

Lime

vbYellow

Yellow

vbBlue

Blue

vbMagenta

Magenta

vbCyan

Cyan

vbWhite

White

System Color Constant Equivalents

Visual Basic 6.0

Visual Basic 2005 Equivalent

vb3DDKShadow

ControlDarkDark

vb3DFace

Control

vb3DHighlight

ControlLightLight

vb3DLight

ControlLight

vb3DShadow

ControlDark

vbActiveBorder

ActiveBorder

vbActiveTitleBar

ActiveCaption

vbActiveTitleBarText

ActiveCaptionText

vbApplicationWorkspace

AppWorkspace

vbButtonFace

Control

vbButtonShadow

ControlDark

vbButtonText

ControlText

vbDesktop

Desktop

vbGrayText

GrayText

vbHighlight

Highlight

vbHighlightText

HighlightText

vbInactiveBorder

InactiveBorder

vbInactiveCaptionText

InactiveCaptionText

vbInactiveTitleBar

InactiveCaption

vbInactiveTitleBarText

InactiveCaptionText

vbInfoBackground

Info

vbInfoText

InfoText

vbMenuBar

Menu

vbMenuText

MenuText

vbScrollBars

ScrollBar

vbTitleBarText

ActiveCaptionText

vbWindowBackground

Window

vbWindowFrame

WindowFrame

vbWindowText

WindowText

When a Visual Basic 6.0 application is upgraded to Visual Basic 2008 using the upgrade wizard, colors are converted using the FromOle method.

After upgrade you should search for any code that explicitly sets the BackColor or ForeColor property at run time. If it is being set for a parent, explicitly set the color of the child controls at design time, otherwise the child controls will inherit the colors from the parent.

Any code that used the Palette, PaletteMode, or MaskColor properties will need to be rewritten in Visual Basic 2008.

Community Additions

ADD
Show:
© 2014 Microsoft