BackColor, ForeColor Properties

Specifies the background or foreground color used to display text and graphics in an object. Read/write at design and run time.

Object.BackColor[ = nColor]
Object.ForeColor[ = nColor]

Property Values

  • nColor
    Specifies a single color value. If nColor is a negative value, Visual FoxPro uses the integer and ignores any rollover issues. For example, -1 is the equivalent of 0xFFFFFFFF. The following table lists typical color values.
    Color RGB values nColor
    White 255, 255, 255 16777215
    Black 0, 0, 0 0
    Gray 192, 192, 192 12632256
    Dark gray 128, 128, 128 8421504
    Red 255, 0, 0 255
    Dark red 128, 0, 0 128
    Yellow 255, 255, 0 65535
    Dark yellow 128, 128, 0 32896
    Green 0, 255, 0 65280
    Dark green 0, 128, 0 32768
    Cyan 0, 255, 255 16776960
    Dark cyan 0, 128, 128 8421376
    Blue 0, 0, 255 16711680
    Dark blue 0, 0, 128 8388608
    Magenta 255, 0 ,255 16711935
    Dark magenta 128, 0, 128 8388736

Remarks

Visual FoxPro uses a red-green-blue (RGB) color scheme for colors. The red, green, and blue components are each represented by a number between 0 and 255. Use the RGB( ) function to convert the three component colors into one composite nColor.

Note   The ForeColor property does not apply to the CommandGroup, OptionGroup, or Shape controls.

The color settings, or Themes, of the operating system set the default color settings for the BackColor and ForeColor properties.

If the Themes property is True (.T.), setting the BackColor property value produces a 35% transparency overlay on top of the themed button. This produces a colorizing effect.

The PageBackColor property is disregarded if PageThemes is True (.T.). However, because a page is only a visual representation in the Class Designer, the back color appears.

Example

The following example demonstrates how the Shape control can be used to display a circle, ellipse, or square on a form, and how the BackColor property can be used to specify the color of each shape.

A form is created, and a set of option buttons and a command button are placed on the form. When you choose one of the option buttons, the corresponding shape is displayed on the form. The BackColor property is used to specify the color of each shape. The Height, Width, and Curvature properties of each shape determine the type of shape created.

frmMyForm = CREATEOBJECT('Form')  && Create a Form
frmMyForm.Closable = .F.  && Disable the Control menu box 

frmMyForm.AddObject('cmdCommand1','cmdMyCmndBtn')  && Add Command button
frmMyForm.AddObject('opgOptionGroup1','opgMyOptGrp') && Add Option Group
frmMyForm.AddObject('shpCircle1','shpMyCircle')  && Add Circle Shape
frmMyForm.AddObject('shpEllipse1','shpMyEllipse')  && Add Ellipse Shape
frmMyForm.AddObject('shpSquare','shpMySquare')  && Add Box Shape

frmMyForm.cmdCommand1.Visible =.T.  && "Quit" Command button visible

frmMyForm.opgOptionGroup1.Buttons(1).Caption = "\<Circle"
frmMyForm.opgOptionGroup1.Buttons(2).Caption = "\<Ellipse"
frmMyForm.opgOptionGroup1.Buttons(3).Caption = "\<Square"
frmMyForm.opgOptionGroup1.SetAll("Width", 100) && Set Option group width
frmMyForm.opgOptionGroup1.Visible = .T.  && Option Group visible
frmMyForm.opgOptionGroup1.Click  && Show the circle

frmMyForm.SHOW  && Display the form
READ EVENTS  && Start event processing

DEFINE CLASS opgMyOptGrp AS OptionGroup  && Create an Option Group
   ButtonCount = 3  && Three Option buttons
   Top = 10
   Left = 10
   Height = 75
   Width = 100

   PROCEDURE Click 
      ThisForm.shpCircle1.Visible = .F.  && Hide the circle
      ThisForm.shpEllipse1.Visible = .F.  && Hide the ellipse
      ThisForm.shpSquare.Visible = .F.  && Hide the square
      
      DO CASE
         CASE ThisForm.opgOptionGroup1.Value = 1
            ThisForm.shpCircle1.Visible = .T. && Show the circle
         CASE ThisForm.opgOptionGroup1.Value = 2 
            ThisForm.shpEllipse1.Visible = .T.  && Show the ellipse
         CASE ThisForm.opgOptionGroup1.Value = 3 
            ThisForm.shpSquare.Visible = .T.  && Show the square
      ENDCASE
ENDDEFINE

DEFINE CLASS cmdMyCmndBtn AS CommandButton  && Create Command button
   Caption = '\<Quit'  && Caption on the Command button
   Cancel = .T.  && Default Cancel Command button (Esc)
   Left = 125  && Command button column
   Top = 210  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      CLEAR EVENTS  && Stop event processing, close Form
ENDDEFINE

DEFINE CLASS shpMyCircle AS SHAPE  && Create a circle
   Top = 10
   Left = 200
   Width = 100
   Height = 100
   Curvature = 99
   BackColor = RGB(255,0,0)  && Red
ENDDEFINE

DEFINE CLASS shpMyEllipse AS SHAPE  && Create an ellipse
   Top = 35
   Left = 200
   Width = 100
   Height = 50
   Curvature = 99
   BackColor = RGB(0,128,0)  && Green
ENDDEFINE

DEFINE CLASS shpMySquare AS SHAPE  && Create a square
   Top = 10
   Left = 200
   Width = 100
   Height = 100
   Curvature = 0
   BackColor = RGB(0,0,255)  && Blue
ENDDEFINE

See Also

BackStyle Property | ColorScheme Property | DisabledBackColor, DisabledForeColor Properties | FillColor Property | FillStyle Property | GETCOLOR( ) Function | RGB( ) Function

Applies To: CheckBox Control | Column Object | ComboBox Control | CommandButton Control | CommandGroup Control | Container Object | Control Object | EditBox Control | Form Object | Grid Control | Header Object | Label Control | OptionButton Control | OptionGroup Control | Page Object | _SCREEN | Shape Control | Spinner Control | TextBox Control | ToolBar Object