The Delphi Column 

Colors in Delphi

In this column, we have a detailed look at colors in Delphi.

The type TColor is used to specify the color of a control. It is used by the Color property of many components and by a number of other properties that specify color values.

Color constants

Delphi contains definitions of constants for standard TColor values. These constants map either directly to the closest matching color in the system palette (for example, clBlue maps to blue) or to the corresponding system screen element color defined in the Color section of Windows' Control Panel (for example, clBtnFace maps to the system color for button faces).

If you specify a TColor as a 4-byte hexadecimal number instead of using a pre-defined constant, the lower three bytes represent the RGB color intensities for blue, green, and red, respectively. The bytes are arranged as 0x00BBGGRR.

Some of the color constants (only a small sample of many more that are available):
Constant  Color  Hex value  RGB values
Red Green Blue
clAqua Aqua   0x00FFFF00 0 255 255
clBlack Black   0x00000000 0 0 0
clBlue Blue   0x00FF0000 0 0 255
clCream Cream   0x00F0FBFF 255 251 240
clGray Grey   0x00808080 128 128 128
clFuchsia Fuchsia   0x00FF00FF 255 0 255
clGreen Green   0x00008000 0 128 0
clLime Lime green   0x0000FF00 0 255 0
clMaroon Maroon   0x00000080 128 0 0
clNavy Navy   0x00800000 0 0 128
clOlive Olive green   0x00008080 128 128 0
clPurple Purple   0x00FF00FF 255 0 255
clRed Red   0x000000FF 255 0 0
clSilver Silver   0x00C0C0C0 192 192 192
clTeal Teal    0x00808000 0 128 128
clWhite White    0x00FFFFFF 255 255 255

The function RGB()

You can also specify a color by using the function RGB() that returns a TColor value. The function takes 3 parameters, one for red, one for green and one for blue, that can range from 0 to 255. Example:

Panel1.Color := TColor(RGB(255, 255, 0))

Color of a component

Some code examples for setting the color of components:

var Colr: TColor;
Panel1.Color := clRed;
Panel2.Color := TColor(0x006CFF6C);
Panel3.Color := RGB(250, 250, 180);
Colr := TColor(RGB(255, 255, 0));
Panel4.Color := Colr;

You can also set the color of a Font:

var Colr: TColor;
Colr := TColor(RGB(0, 0, 180));
Font.Color := Colr; // Font of the form
Label1.Font.Color := clBlue;
Memo1.Font.Color := TColor(RGB(0, 110, 0));


Database Tutorials  FAQ  Crash Course Delphi  Tips  Source Code  Downloads  Links

Copyright 1999-2022 
DelphiLand