The information in this article applies to:
- Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
- Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6
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:
- Open the CUSTOMER.DBF database located in the TUTORIAL subdirectory.
- Create a screen and choose Quick Screen from the Screen menu.
- 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
- 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.
|