KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to reference the default 4D color palette
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: February 14, 2007
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

4D allows developers to programmatically set colors to objects. One of the ways to do so is to use the SET COLOR command. The SET COLOR command works with indexed colors within the default 4D color palette. Currently, 4D provides the following constants for the first 16 colors of the palette.



As shown above, 4D references 16 out of the 256 possible colors on the palette. So how does one reference the other colors?



The picture above shows each color in the palette referenced by a number. One just needs to count from left to right and top to bottom. The numbers on the left help isolate the group of numbers for a given row. As an example, I would like to procedurally change my foreground color of my text field to black and the background color to the following:



The background color belongs on row 112-127 on the palette. To get the exact reference number, simply start counting from the left of that row and make your way to the right until you reach the color chosen. Therefore, the first color in that row would be 112, the next color to the right would be 113, and so on. Since the color I chose is 113, this is the reference number I will use in the SET COLOR command. Below is the code to change the color for my text field:


C_LONGINT(color)
color:=- (black + (256 * 113))
SET COLOR (*;"Mytext"; color)


After the above code is executed, the field will display as:



NOTE: The color value in the SET COLOR command is calculated using the following formula:


Color:=-(Foreground+(256 * Background))


Related Sources:

-The SET RGB COLORS command
-The SET COLOR command
-Tech Tip: Find and match any color
-Tech Tip: Changing the foreground and background color of an object
-Tech Tip: How do I change background colors of form objects?
-Tech Tip: Using color in output forms