DataType

Color


Description

The data type for storing Color values with an optional alpha component.

Properties

Name

Type

Read-Only

Shared

Alpha

Integer

Blue

Integer

Cyan

Double

Green

Integer

Hue

Double

Magenta

Double

Red

Integer

Saturation

Double

Value

Double

Yellow

Double

Methods

Name

Parameters

Returns

Shared

AccentThemeColor

Color

CMY

cyan As Double, magenta As Double, yellow As Double, alpha As Integer = 0

Color

DarkBevelColor

Color

DarkTingeColor

Color

DisabledTextColor

Color

FillColor

Color

FrameColor

Color

FromString

hexString As String

Color

HighlightColor

Color

HSV

hue As Double, saturation As Double, value As Double, alpha As Integer = 0

Color

IsDarkMode

Boolean

LightBevelColor

Color

LightTingeColor

Color

PrimaryThemeColor

Color

RGB

red As Integer, green As Integer, blue As Integer, alpha As Integer = 0

Color

SelectedFromDialog

ByRef selectedColor As Color, prompt As String

Boolean

TextColor

Color

ToString

String

Constants

The following class constants can be used to specify a color without having to instantiate a Color object:

Class Constant

Black

Blue

Clear

Cyan

DarkGray

Gray

Green

LightGray

Magenta

Orange

Purple

Red

Teal

White

Yellow

Property descriptions


Color.Alpha

Alpha As Integer

The alpha channel is the translucency of the Color represented as an integer between 0 (opaque) and 255 (transparent).

This property is read-only.


Color.Blue

Blue As Integer

The amount (0-255) of blue in the Color (RGB).

This property is read-only.


Color.Cyan

Cyan As Double

The value of Cyan (0-1) in the Color (CMY).

This property is read-only.


Color.Green

Green As Integer

The amount (0-255) of green in the Color (RGB).

This property is read-only.


Color.Hue

Hue As Double

The value of Hue (0-1) in the Color (HSV).

This property is read-only.


Color.Magenta

Magenta As Double

The value of Magenta (0-1) in the Color (CMY).

This property is read-only.


Color.Red

Red As Integer

The amount (0-255) of red in the Color (RGB).

This property is read-only.


Color.Saturation

Saturation As Double

The value of Saturation (0-1) in the Color (HSV).

This property is read-only.


Color.Value

Value As Double

The value of Value (0-1) in the Color (HSV).

This property is read-only.


Color.Yellow

Yellow As Double

The value of Yellow (0-1) in the Color (CMY).

This property is read-only.

Method descriptions


Color.AccentThemeColor

AccentThemeColor() As Color

Returns the Color used to accent items in the interface. This color is set in the OS itself.

Important

This method is supported for Android only.


Color.CMY

CMY(cyan As Double, magenta As Double, yellow As Double, alpha As Integer = 0) As Color

Returns a Color based on the CMY (cyan, magenta, yellow) Color model and the specified level of transparency. Use the new form of the Picture constructor to create pictures that support the alpha channel or convert existing pictures to the new format using the code described in HasAlphaChannel.

This method is shared.

The CMY function returns a Color based on the amounts of Cyan, Magenta, Yellow, and transparency passed. The Color amounts are represented by doubles between 0 and 1 and are stored internally as three bytes. The level of transparency is an optional Integer from 0-255. If omitted, it defaults to completely opaque. You can also use either the RGB or HSV models to assign a Color and you can also specify a Color with the RGB model using the &c literal. All alternatives support the optional transparency parameter.

This code uses the CMY function to assign a Color. It is in the Paint event of a Canvas or a DesktopWindow.

Rectangle1.FillColor = Color.CMY(0.35, 0.9, 0.6, 0)

The following code draws a Color patch in a Canvas with 75% transparency. With the CMY function, the range is from 0 to 255. Zero is completely opaque and 255 is completely transparent. The code is in the Paint event.

g.DrawingColor = Color.CMY(0.0, 1.0, 1.0, 255 * 0.75) ' transparency = 75%

g.FillRectangle(0, 70, 200, 50)
g.DrawingColor = Color.CMY(0.0, 0.0, 0.0)
g.DrawText("Translucent = 30%", 210, 80)

Color.DarkBevelColor

DarkBevelColor As Color

The currently selected operating systems Color for drawing dark lines in Groupboxes.

This method is shared.

Note

This Color value does not change when IsDarkMode is True.

Important

This method is not currently supported for Android.

This value is useful when you are using Canvas controls to create custom controls. When drawing controls like GroupBoxes, use this Color for the dark portions of the object (usually the right and bottom sides of the object).

This value can be changed by the user, so you should access this value in the Paint event handler rather than storing the value.

The following example uses the LightBevelColor and DarkBevelColor in a Canvas object that has a raised 3D look. This code is in the Paint event.

Const White = &cffffff
g.DrawingColor = White
g.DrawLine(1, 1, Canvas1.Width, 1)
g.DrawLine(1, Canvas1.Height - 1, 1, 1)
g.DrawingColor = Color.DarkBevelColor
g.DrawLine(Canvas1.Width - 1, 2, Canvas1.Width-1, Canvas1.Height)
g.DrawLine(1, Canvas1.Height - 1, Canvas1.Width, Canvas1.Height - 1)

' fill in the light gray rectangle
g.DrawingColor = Color.LightBevelColor
g.FillRectangle(2, 2, Canvas1.Width - 3, Canvas1.Height - 3)

Color.DarkTingeColor

DarkTingeColor As Color

The currently selected Color for drawing dark lines inside frames on the bottom and right sides.

This method is shared.

Note

This Color value does not change when IsDarkMode is True.

Important

This method is not currently supported for Android.

This value is useful when you are using Canvas controls to create custom controls. When drawing beveled objects, use this Color for the dark portions of the object (usually the right and bottom sides of the object). In a CheckBox control, this Color is used to draw the dark lines that give it the beveled appearance just inside the checkbox on the right and bottom sides.

This value can be changed by the user, so you should access this value in the Paint event handler rather than storing the value.

The following example uses the DarkTingeColor to shade the bottom and right sides of the rectangle.

Const White = &cffffff
g.DrawingColor = White
g.DrawLine(1, 1, Canvas1.Width, 1)
g.DrawLine(1, Canvas1.Height - 1, 1, 1)
g.DrawingColor = Color.DarkTingeColor
g.DrawLine(Canvas1.Width - 1, 2, Canvas1.Width - 1, Canvas1.Height)
g.DrawLine(1, Canvas1.Height - 1, Canvas1.Width, Canvas1.Height - 1)
' fill in the light gray rectangle
g.DrawingColor = Color.LightTingeColor
g.FillRectangle(2, 2, Canvas1.Width - 3, Canvas1.Height - 3)

Color.DisabledTextColor

DisabledTextColor As Color

The currently selected Color for drawing disabled text in a window. By default it is a light gray.

This method is shared.

This value is useful when you want to assign the system graytext Color to disabled text.

This usage of DisabledTextColor affects the second text string. The code is in the Paint event of a DesktopCanvas.

g.DrawText("This is my text", 10,10, 100, False) ' enabled text color

g.DrawingColor = Color.DisabledTextColor
g.DrawText("This is my text", 10, 50, 100, False) ' disabled text color

Color.FillColor

FillColor As Color

The system's window background Color.

This method is shared.

This value is useful when you are using Canvas controls to create custom controls. When drawing objects, use this Color to fill the background.

This value can be changed by the user or when the system changes between light and dark modes, so you should use this method in the Paint event handler rather than storing the value.

FillColor matches the default Window Background on all platforms, except for macOS in DarkMode. Use Graphics.ClearRectangle to properly clear the window so that it's background Color displays when using Dark Mode.

This example uses the system fill Color to set the Color of a square with a 3D "raised" look. The code is in the Paint event of a Canvas.

Const White = &cffffff
Const DarkGray = &c8c8c8c

g.DrawingColor = White
g.DrawLine(1, 1, Me.Width, 1)
g.DrawLine(1, Me.Height - 1, 1, 1)
g.DrawingColor = DarkGray
g.DrawLine(Me.Width - 1, 2, Me.Width - 1, Me.Height)
g.DrawLine(1, Me.Height - 1, Me.Width, Me.Height - 1)

' Fill in using the system Fill color
g.DrawingColor = Color.FillColor
g.FillRectangle(2, 2, Me.Width - 3, Me.Height - 3)

Color.FrameColor

FrameColor As Color

The Color used for drawing the outline of a DesktopUIControl.

This method is shared.

This value is useful when you are using Canvas controls to create custom controls. When drawing objects, use this Color for the object's frame. ListBoxes, for example, use this Color to draw the frame around the ListBox.

This value can be changed by the user or when the system switches between light and dark modes, so you should use this method in your Paint Event handler rather than storing the value.

This code uses the system FrameColor to draw the bottom and right of this object. The code is in the Paint event of the Canvas.

Const White = &cffffff

g.DrawingColor = White

g.DrawLine(1, 1, g.Width, 1)
g.DrawLine(1, g.Height - 1, 1, 1)
g.DrawingColor = Color.FrameColor
g.DrawLine(g.Width - 1, 2, g.Width - 1, g.Height)
g.DrawLine(1, g.Height - 1, g.Width, g.Height - 1)
' Fill in using the system Fill color
g.DrawingColor = Color.FillColor
g.FillRectangle(2, 2, g.Width - 3, g.Height - 3)

Color.FromString

FromString(hexString As String) As Color

Returns a Color from a hex string value.

This method is shared.


Color.HighlightColor

HighlightColor As Color

Returns the operating system's highlight Color.

This method is shared.

On Windows, the highlight Color can be modified via the Display Control Panel. In macOS, the highlight Color is set in the General System Preferences panel. On Linux, the highlight Color is affected by the user's Window Manager and themes.

Note

This property is not supported for iOS.

The following example uses the system highlight Color to fill in a rectangle. The code is in the Paint event of a Canvas.

Const White = &cffffff

g.DrawingColor = White
g.DrawLine(1, 1, g.Width, 1)
g.DrawLine(1, g.Height - 1, 1, 1)
g.DrawingColor = Color.DarkBevelColor
g.DrawLine(g.Width - 1, 2, g.Width - 1, g.Height)
g.DrawLine(1, g.Height - 1, g.Width, g.Height - 1)
' fill in the  rectangle
g.DrawingColor = Color.HighlightColor
g.FillRectangle(2, 2, g.Width - 3, g.Height - 3)

Color.HSV

HSV(hue As Double, saturation As Double, value As Double, alpha As Integer = 0) As Color

Returns a Color from hue, saturation and value. These values are represented by Doubles between 0 and 1.

This method is shared.

The alpha parameter provides the ability to control transparency and is an integer between 0 and 255. Zero is completely opaque and 255 is transparent. If omitted, the default is 0 (no transparency).

Set a Color using hue, saturation and value:

Var c As Color = Color.HSV(0.8, 0.5, 0.75)

Color.IsDarkMode

IsDarkMode As Boolean

True when the device is currently in dark mode, otherwise False.

This method is shared.


Color.LightBevelColor

LightBevelColor As Color

The currently selected operating system Color for drawing light lines in dividing lines and group boxes.

This method is shared.

Note

This Color value does not change when IsDarkMode is True.

Important

This method is not currently supported for Android.

This value is useful when you are using Canvas controls to create custom controls. When drawing controls like GroupBoxes, use this Color for the light portions of the object (usually the top and left sides of the object).

This value can be changed by the user, so you should access this value in the Paint event handler rather than storing the value.

The following example uses the methods LightBevelColor and DarkBevelColor in a Canvas object that has a raised 3D look. This code is in the Canvas.Paint event.

Const White = &cffffff

g.DrawingColor = White
g.DrawLine(1, 1, g.Width, 1)
g.DrawLine(1, g.Height - 1, 1, 1)
g.DrawingColor = Color.DarkBevelColor
g.DrawLine(g.Width - 1, 2, g.Width - 1, g.Height)
g.DrawLine(1, g.Height - 1, g.Width, g.Height - 1)
' fill in the light gray rectangle
g.DrawingColor = Color.LightBevelColor
g.FillRectangle(2, 2, g.Width - 3, g.Height - 3)

Color.LightTingeColor

LightTingeColor As Color

The currently selected operating system Color for drawing light lines inside frames on the top and left sides.

This method is shared.

Note

This Color value does not change when IsDarkMode is True.

Important

This method is not currently supported for Android.

This value is useful when you are using Canvas controls to create custom controls. When drawing beveled objects, use this Color for the light portions of the object (usually the top and left sides of the object). In a DesktopCheckBox control, this Color is used to draw the light lines that give it the beveled appearance just inside the checkbox on the top and left sides.

This value can be changed by the user, so you should access this value in the Paint event handler rather than storing the value.

The following example uses the LightTingeColor to shade the top and left sides of the rectangle.

Const White = &cffffff

g.DrawingColor = White
g.DrawLine(1, 1, g.Width, 1)
g.DrawLine(1, g.Height - 1, 1, 1)
g.DrawingColor = Color.DarkBevelColor
g.DrawLine(g.Width - 1, 2, g.Width - 1, g.Height)
g.DrawLine(1, g.Height - 1, g.Width, g.Height - 1)
' fill in the light gray rectangle
g.DrawingColor = Color.LightTingeColor
g.FillRectangle(2, 2, g.Width - 3, g.Height - 3)

Color.PrimaryThemeColor

PrimaryThemeColor() As Color

Returns the Color used as the primary color in the interface. The background of the navigation bar uses this color. This color is set in the OS itself.

Important

This method is supported for Android only.


Color.RGB

RGB(red As Integer, green As Integer, blue As Integer, alpha As Integer = 0) As Color

Returns a Color based on the specified red, green, blue values.

This method is shared.

The alpha parameter provides the ability to control transparency and is an integer between 0 and 255. Zero is completely opaque and 255 is transparent. If omitted, the default is 0 (no transparency).

Set a Color variable to red:

Var red As Color = Color.RGB(255, 0, 0)

Color.SelectedFromDialog

SelectedFromDialog(ByRef selectedColor As Color, prompt As String) As Boolean

Displays the system Color Picker, allowing the user to choose a Color.

Note

On Windows and Linux, the operating system's color picker window is modal. On macOS, the color picker is not modal.

This method is shared.

Important

This method is not supported for iOS and Android.

The color picker can also be displayed via the DesktopColorPicker class.

You control the default choice of Color displayed by the Color Picker by passing a value of col to SelectColor. If col is not assigned a value, black is used as the default Color. The Color that the user chooses is returned in col. If the user clicks Cancel without making a choice, result is set to False; otherwise it is set to True.

The following example allows the user to select a Color that will be used as the fillcolor in a Rectangle control.

Var c  As Color
Var b As Boolean
c = Color.CMY(0.35, 0.9, 0.6, 0) ' choose the default color shown in color picker
b = Color.SelectedFromDialog(c, "Select a Color")
Rectangle1.FillColor = c

If you don't want to test the boolean returned by SelectedFromDialog, you can call it using Call.

Call Color.SelectedFromDialog(c, "Select a Color")

Color.TextColor

TextColor As Color

The system text Color.

This method is shared.

This value is useful when you are using Canvas controls to create custom controls. When drawing objects, use this Color as the DrawingColor value when drawing text.

The DisabledTextColor returns the system Color for drawing disabled text.

This value can be changed by the user or when the system switches between light/dark modes, so you should use this method in the Paint event handler rather than storing the value.


Color.ToString

ToString As String

Converts the Color to a hex String value.

Notes

The default value of a Color is &c000000 (black).

Colors are often used to assign colors to properties of type Color. Use the RGB, HSV, or CMY functions to assign a Color to an object or use the format:

&cRRGGBB

In the above, RR is the RGB value of Red in hexadecimal, GG is the value Green in hexadecimal, and BB is the value of Blue in hexadecimal. You can right-click in the Code Editor and select Insert Color to choose a Color using the Color picker, which will insert the hexadecimal value at the cursor position in the editor.

Desktop, Web and Console projects can also use the CMY function to set the Color using cyan, magenta and yellow elements. The CMY function is not available for iOS projects.

You can use the VarType function to determine whether a property or a variable is a Color. If it is, VarType returns 16.


Converting to/from hex strings

Use the ToString function to get the hexadecimal RGB value of a Color:

Var c1 As Color
c1 = Color.RGB(255, 100, 50)
Var hexColor As String = c1.ToString ' hexColor = &h00FF6432

Note that a hex Color has the alpha value at the front instead of the end like an &c Color does.

To convert a hexadecimal Color value back to a Color, use the FromString shared method like this:

' hexColor is the String from above that contains a hex color value
Var c2 As Color = Color.FromString(hexColor)

Alpha channel support

The Color type has a read-only "Alpha" property. The alpha channel is the transparency of the Color represented as an integer between 0 (opaque) and 255 (transparent).

The Color literal syntax can optionally have two more hexadecimal digits at the end representing the alpha channel (for example, "&cFF00007F"). If the Color literal has only 3 channels of information, the alpha component defaults to 0.

&cRRGGBBAA

The RGB, HSV, and CMY functions also have an optional integer parameter that specifies the alpha channel for the Color.

Sample code

The following example uses the RGB model to set the DrawingColor property of a Canvas control and draw a square using the current DrawingColor. The code is placed in the Canvas control's Paint event.

g.DrawingColor = Color.RGB(255, 0, 0)
g.DrawRectangle(0, 0, 50, 50)

The following example (in a Canvas Paint event) assigns a Color directly using the RGB Color model. The RGB values must be specified in hexadecimal:

g.DrawingColor = &cFF0000
g.DrawRectangle(0, 0, 50, 50)

The following example uses the CMY model to set the FillColor of a Rectangle control, r.

r.FillColor = Color.CMY(0.1, 0.3, 0.5)

The following example inverts the FillColor:

Var c As Color
c = Color.RGB(255 - r.FillColor.Red, 255 - r.FillColor.Green,  255 - r.FillColor.Blue)
r.FillColor = c

Compatibility

All project types on all supported operating systems.

See also

Str, String, VarType functions; &c literal; ColorGroup class