Working With Colors

Applies to TestComplete 15.69, last modified on November 13, 2024

TestComplete lets you use various color values in scripts. Any color value is represented is a 4-byte integer value (usually, in a hexadecimal format), where the low 3 bytes represent intensities for blue, green and red components respectively. For example, the Sky Blue color is represented by the F0CAA6 hexadecimal value (&hF0CAA6 in VBScript, 0xF0CAA6 in JavaScript, JScript, Python, C++Script and C#Script, $F0CAAF in DelphiScript), where F0 (hexadecimal value of 240) is blue component, CA (hexadecimal value of 202) is green component and A6 (hexadecimal value of 166) is red component.

In order to make use of color values more convenient, TestComplete provides a number of predefined constants for most frequently used colors. These constants are defined in the BuiltIn object and represent common colors (such as white, black and others) as well as Windows display elements (for example, the color of the window’s background). The constants are available in the Code Completion window and have the cl prefix. Since these constants are defined in the BuiltIn object, you can omit the object name when using the constants in scripts. For example, the following two lines are equivalent:

JavaScript, JScript

color = BuiltIn.clSkyBlue;
color = clSkyBlue;

Python

color = BuiltIn.clSkyBlue
color = clSkyBlue

VBScript

color = BuiltIn.clSkyBlue
color = clSkyBlue

DelphiScript

color := BuiltIn.clSkyBlue;
color := clSkyBlue;

C++Script, C#Script

color = BuiltIn.clSkyBlue;
color = clSkyBlue;

If your scripts are wrote in VBScript, you can also use built-in VBScript color constants. They are also available in the Code Completion window.

The following sections list available color constants and also give instructions on how to specify custom colors.

Common Colors

The following constants defined in the BuiltIn object represent common colors that are mapped to the closest colors in the system palette.

Constant RGB Value Value Example Description
VBScript JavaScript, JScript,
C++Script,
C#Script
DelphiScript
clAqua 0, 255, 255 &hFFFF00 0xFFFF00 $FFFF00   Aqua (Cyan)
clBlack 0, 0, 0 &h000000 0x000000 $000000   Black
clBlue 0, 0, 255 &hFF0000 0xFF0000 $FF0000   Blue
clCream 255, 251, 240 &hF0FBFF 0xF0FBFF $F0FBFF   Cream
clDefault   &h20000000 0x20000000 $20000000   Default color for the given case (for example, default color of button face or window background)
clDkGray 128, 128, 128 &h808080 0x808080 $808080   Gray
clGray 128, 128, 128 &h808080 0x808080 $808080   Gray
clFuchsia 255, 0, 255 &hFF00FF 0xFF00FF $FF00FF   Fuchsia (Magenta)
clGreen 0, 128, 0 &h008000 0x008000 $008000   Green
clLime 0, 255, 0 &h00FF00 0x00FF00 $00FF00   Lime
clLtGray 192, 192, 192 &hC0C0C0 0xC0C0C0 $C0C0C0   Light Gray (Silver)
clMaroon 128, 0, 0 &h000080 0x000080 $000080   Maroon
clMedGray 160, 160, 164 &hA4A0A0 0xA4A0A0 $A4A0A0   Medium Gray
clMoneyGreen 192, 220, 192 &hC0DCC0 0xC0DCC0 $C0DCC0   Money Green
clNavy 0, 0, 128 &h800000 0x800000 $800000   Navy
clNone   &h1FFFFFFF 0x1FFFFFFF $1FFFFFFF   No color
clOlive 128, 128, 0 &h008080 0x008080 $008080   Olive
clPurple 128, 0, 128 &h800080 0x800080 $800080   Purple
clRed 255, 0, 0 &h0000FF 0x0000FF $0000FF   Red
clSilver 192, 192, 192 &hC0C0C0 0xC0C0C0 $C0C0C0   Light Gray (Silver)
clSkyBlue 166, 202, 240 &hF0CAA6 0xF0CAA6 $F0CAA6   Sky Blue
clTeal 0, 128, 128 &h808000 0x808000 $808000   Teal
clWhite 255, 255, 255 &hFFFFFF 0xFFFFFF $FFFFFF   White
clYellow 255, 255, 0 &h00FFFF 0x00FFFF $00FFFF   Yellow

System Colors

The following constants defined in the BuiltIn object represent colors of system screen elements. These colors are defined in the Display Properties | Appearance section of the Control Panel.

Constant Description
cl3DDkShadow Color of the right and bottom edges for three-dimensional display elements.
cl3DLight Color of the top and left edges for three-dimensional display elements.
clActiveBorder Color of the active window’s border.
clActiveCaption Color of the active window’s title bar.
clAppWorkSpace Background color of a multiple document application (MDI) workspace.
clBackground Background color of the Windows desktop.
clBtnFace Background color of buttons.
clBtnHighlight Color or top and left edges of buttons.
clBtnShadow Color of right and bottom edges of buttons.
clBtnText Color of text on push buttons.
clCaptionText Color of the text in the active window’s title bar.
clGradientActiveCaption Right-side gradient color of the active window’s title bar.
clGradientInactiveCaption Right-side gradient color of an inactive window’s title bar.
clGrayText Color of the dimmed text.
clHighlight Background color of the text selected in a component.
clHightlightText Color of the text selected in a component.
clHotText Color of the hot-tracked item (hovered by a mouse pointer).
clInactiveBorder Color of the border of inactive windows.
clInactiveCaption Color of the title bar of an inactive windows.
clInactiveCaptionText Color of the text in the title bar of an inactive window.
clInfoBk Background color of tooltips.
clInfoText Color of the tooltip’s text.
clMenu Background color of menu items.
clMenuBar Background color of menu bars.
clMenuHighlight Color of hot-tracked menu item.
clMenuText Color of the text in menus.
clScrollBar Background color of scrollbars.
clWindow Background color of windows.
clWindowFrame Color of window frames.
clWindowText Color of the text in windows.

VBScript Built-In Colors

The following built-in VBScript constants represent some common colors. You can use these constants in your scripts written in VBScript, without the need to define them. These constants are available in the Code Completion window, if the button is pressed.

Constant Value Example Description
vbBlack &h000000   Black
vbBlue &hFF0000   Blue
vbCyan &hFFFF00   Cyan (Aqua)
vbGreen &h00FF00   Lime Green
vbMagenta &hFF00FF   Magenta (Fuchsia)
vbRed &h0000FF   Red
vbWhite &hFFFFFF   White
vbYellow &h00FFFF   Yellow

Specifying Custom Colors

In order to calculate the value of a custom color, you need to know the exact values of the red, green and blue components of that color and create a script routine that will convert them into a single color value.

The following code example assigns the variable with the Orange color value, whose RGB value is 255, 165, 0. The RGB function calculates the color value out of its RGB components.

JavaScript, JScript

function CorrectRGBComponent(component)
{
  component = aqConvert.VarToInt(component);
  if (component < 0)
    component = 0;
  else
    if (component > 255)
      component = 255;
  return component;
}

function RGB(r, g, b)
{
  r = CorrectRGBComponent(r);
  g = CorrectRGBComponent(g);
  b = CorrectRGBComponent(b);
  return r | (g << 8) | (b << 16);
}

function Test ()
{
  var Orange;
  Orange = RGB (255, 165, 0);
}

Python

def CorrectRGBComponent(component):
  component = aqConvert.VarToInt(component)
  if component < 0:
    component = 0
  else:
    if component > 255:
      component = 255
  return component

def RGB(r, g, b):
  r = CorrectRGBComponent(r)
  g = CorrectRGBComponent(g)
  b = CorrectRGBComponent(b)
  return r | (g << 8) | (b << 16)

def Test():
  Orange = RGB(255, 165, 0)

VBScript

Sub CorrectRGBComponent(ByRef component)
  component = aqConvert.VarToInt(component)
  If (component < 0) Then
    component = 0
  Else
    If (component > 255) Then
      component = 255
    End If
  End If
End Sub

Function RGB(r, g, b)
  Call CorrectRGBComponent(r)
  Call CorrectRGBComponent(g)
  Call CorrectRGBComponent(b)
  RGB = r + (g * 256) + (b * 65536)
End Function

Sub Test
  Orange = RGB (255, 165, 0)
End Sub

DelphiScript

procedure CorrectRGBComponent(var component);
begin
  component := aqConvert.VarToInt(component);
  if (component < 0) then
    component := 0
  else
    if (component > 255) then
      component := 255;
end;

function RGB(r, g, b) : integer;
begin
  CorrectRGBComponent(r);
  CorrectRGBComponent(g);
  CorrectRGBComponent(b);
  Result := r or (g shl 8) or (b shl 16);
end;

procedure Test;
var Orange : integer;
begin
  Orange := RGB (255, 165, 0);
end;

C++Script, C#Script

function CorrectRGBComponent(component)
{
  component = aqConvert["VarToInt"](component);
  if (component < 0)
    component = 0;
  else
    if (component > 255)
      component = 255;
  return component;
}

function RGB(r, g, b)
{
  r = CorrectRGBComponent(r);
  g = CorrectRGBComponent(g);
  b = CorrectRGBComponent(b);
  return r | (g << 8) | (b << 16);
}

function Test ()
{
  var Orange;
  Orange = RGB (255, 165, 0);
}

Highlight search results