How to Change a Field Color Based on the Field's Contents

ID: Q114254

2.50 2.50a 2.50b 2.60 | 2.00 2.50 2.50a 2.50b 2.60

WINDOWS               | MS-DOS
kbprg

The information in this article applies to:

SUMMARY

This article describes how to change the color of a field based on its contents. Changing the color of a field based on what it contains may be useful to users who are scrolling through the records in an input screen.

MORE INFORMATION

To create the screen, do the following:

1. Open the CUSTOMER.DBF database located in the TUTORIAL subdirectory.

2. Create a screen and choose Quick Screen from the Screen menu.

3. Add two push buttons to the screen with the variable name M.CHOICE.

   Give the push button two prompts called PRIOR and NEXT. Enter the
   following code in the VALID clause:

      DO CASE
         CASE m.choice = 1
            SKIP - 1
         CASE m.choice = 2
            SKIP
      ENDCASE
      SHOW GETS

4. If you are using FoxPro for Windows, choose Layout from the Screen menu.
   Choose the Code push button and add the following code in the On Refresh
   (Show Gets) box:

      IF customer.lat > 35
         SHOW GET customer.lat COLOR ,RGB(255,255,255,255,0,0)
      ELSE
         SHOW GET customer.lat COLOR ,RGB(0,0,0,192,192,192)
      ENDIF

      NOTE: To change the numbers used in the RGB() clause, double-click
      the Color icon in the Windows Control Panel. Choose the Color Palette
      button, select the color you want to know the numbers of, and then
      choose the Define Custom Colors button. The numbers in the Red,
      Green, and Blue boxes are the ones you use with RGB(). The first
      three numbers in the RGB() clause are the foreground and the last
      three numbers are the background.

   If you are using FoxPro for MS-DOS, choose Screen Layout from the Screen
   menu. In the SHOW clause, add the following code:

      IF customer.lat > 35
         SHOW GET customer.lat COLOR +W/R
      ELSE
         SHOW GET customer.lat COLOR +W/BG
      ENDIF

If customer.lat is greater than 35, the field will have a white foreground and red background. If customer.lat is less than 35, the field will have the default colors of a white foreground with cyan background in FoxPro for MS-DOS and a black foreground with gray background in FoxPro for Windows.

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.60 set KBCategory: kbprg KBSubcategory: FxprgGeneral

Keywords          : FxprgGeneral 
Version           : 2.50 2.50a 2.50b 2.60 | 2.00 2.5
Platform          : MS-DOS WINDOWS

Last Reviewed: May 1, 1996