by David Thompson - GUI Computing
A lot of properties that were read only at run time in Access 1.1 are/write at run time on Access 2.0. An example of such properties are ForeColour and BackColour.
Choosing colours for your application is never easy. There is always a user who doesn't like your colours and wants to be able to change them, and there is always the possibility that your hard coded colours might clash horribly with the system colours currently in use. But writing an application where the colours are user configurable is not always practical. One method that avoids both of these problems is to use the system colours for your labels and set them at run time. This requires the use of the API function GetSysColor which conveniently returns a long that can be plugged into the ForeColour and BackColour properties of a label in Access 2.0. Place the following lines in the declarations section of your form:
Declare Function GetSysColor Lib "User" (ByVal nIndex As Integer) As Long Const COLOR_ACTIVECAPTION = 2 Const COLOR_CAPTIONTEXT =9
The function below will colour selected labels on your form so that they look like the caption of an active window. If a control is of type label and the name starts with "lblSys" then the ForeColour and BackColour properties are set to the system colours. The check for "lblSys" is used so that some labels can be deliberately excluded.
Sub SystemColors (F As Form) Dim i As Integer For i = 0 To F.Count - 1 If Typeof F(i) Is Label Then If Left$ (F(i).Name, 6) = "lblSys" Then F (i) .BackColor = GetSysColor (COLOR_ACTIVECAPTION) F (i) .ForeColor = GetSysColor (COLOR_CAPTIONTEXT) End If End If Next i End Sub
The On Open event of a form is an ideal place to set the colours of your labels:
Sub Form_Open (Cancel As Integer) SystemColors Me End Sub
When designing the form all the labels that should be coloured the same
as the window caption should have names starting with "lblSys". There is
no reason this method cannot be used with other controls (eg. Text Boxes)
and other system colours (eg. COLOR_INACTIVECAPTION). Look at the
COLOR_ constants in the Windows SDK for some more ideas.