BackColor, ForeColor Properties

Purpose

BackColor returns or sets the background color of an Ocx object. ForeColor returns or sets foreground color used to display text and graphics in an Ocx object.

Syntax

[Object.]BackColor [ = rgb ]

[Object.]ForeColor [ = rgb ]

Object:Ocx Object
rgb:ivar

Description

When used without an object, the BackColor and ForeColor properties set the colors of the current active form object (Form, LoadForm, Dialog, and OpenW). The current active form is the one that is stored in Me. Me is set automatically after creating a form or by explicitly invoking Set Me = form Object.

As an alternative the colors can be set using the form properties .BackColor and .ForeColor.

For all forms and controls, the default settings are BackColor = colBtnFace and ForeColor = colWindowText.

Note: When using Common Controls version 6, it is NOT possible to change the text colour by setting the ForeColor property of any object of the 'Button' family: these include CheckBoxes, Command buttons, Frames and Option Boxes. In the case of Command buttons, this is also not possible using Common Controls version 5.

Example

OpenW # 1                      // Me = Win_1

ForeColor = QBColor(3)         // refers to Me implicitly

ForeColor = &H808080           // refers to Me implicitly

Me.ForeColor = RGB(92, 92, 92) // use Me explicitly

Win_1.ForeColor = colBtnFace   // use the form's name

There are several methods to define the RGB color value for the form. The RGB()function is one way to define colors, and the QBColor function another. In most cases, it’s much easier to enter these numbers in hexadecimal.

The valid range for a normal RGB color is 0 to 16,777,215 ($FFFFFF). Each color setting (property or argument) is a 4-byte integer. The high byte of a number in this range equals 0. The lower 3 bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 ($FF).

Consequently, you can specify a color as a hexadecimal number using this syntax: $BBGGRR. The BB specifies the amount of blue, GG the amount of green, and RR the amount of red. Each of these fragments is a two-digit hexadecimal number from 00 to FF. The median value is 80. Thus, the following number specifies gray, which has the median amount of all three colors: $808080

For RGB colors, the high byte equals 0 whereas for system colors the high byte equals 8. Setting the most significant bit to 1 changes the meaning of the color value: It no longer represents an RGB color, but an environment-wide color specified through the Windows Control Panel. The values that correspond to these system-wide colors range from &H80000000 to &H80000015. For example, the hexadecimal number used to represent the color of an active window caption is &H80000002. The following constants are predefined:

colScrollBar; colBackGround; colDesktop; colActiveCaption; colInactiveCaption; colMenu; colWindow; colWindowFrame colMenuText; colWindowText; colCaptionText; colActiveBorder; colInactiveBorder; colAppWorkSpace; colHighLight; colHighLightText; col3DFace; col3DShadow; colBtnFace; colBtnShadow; colGrayText; colBtnText; colInactiveCaptionText; colBtnHighLight; colBtnHiLight; col3DHighLight; col3DHiLight; col3DDkShadow; col3DLight; colInfoText; colInfoBk

These color constants define system colors that are recognized by the system by the high order byte value ($80). The translation to a RGB color value happens at system level. A property set to a system color constant remains having the index value! See also GetRValue().

Example

OpenW 1

BackColor = &H80000007

Ocx ListBox lb = , 10, 10, 100, 100

lb.AddItem "Text 1"

.BackColor = colAppWorkSpace

.ForeColor = _minInt + COLOR_HIGHLIGHTTEXT

Do

Sleep

Until Me Is Nothing

Remarks

As an alternative for BackColor and ForeColor for forms you can use the Color, RGBColor, or QBColor commands. The [RGB]Color command takes RGB values (contrary to GFA-BASIC 16).

Color RGB(255, 0, 0), RGB(99, 99, 99)

If you set the BackColor property on a Form object, all text, and graphics, including the persistent graphics, are erased. This does not happen if you use the other color commands. Setting the ForeColor property doesn't affect graphics or print output already drawn. On all other controls, the screen color changes immediately.

See Also

Form, Color, RGBColor, QBColor, GetBValue

{Created by Sjouke Hamstra; Last updated: 03/03/2018 by James Gaite}