Using Colors [4] Property to Set Boolean Colors on LabVIEW Front Panel

Updated Aug 23, 2023

Reported In

Software

  • LabVIEW

Issue Details

I am using the Colors [4] property of a Boolean Control. How can I specify the Control's colors for the different states?

Solution

The Colors [4] property uses an array of six clusters containing two color constants each. The two elements of each cluster are foreground and background RGB (Red, Green, Blue) colors for specific states of the Boolean control.
  • The first cluster of the array represents the Boolean False case colors (foreground and background).
  • The second cluster of the array represents the Boolean True case colors (foreground and background).
  • The third cluster represents the colors of the True to False transition case (foreground and background).
  • The fourth cluster represents the colors of the False to True transition case (foreground and background).
  • The fifth cluster of the array represents the colors of the control while the mouse hovers over it in the Boolean False case (foreground and background).
  • The sixth cluster of the array represents the colors of the control while the mouse hovers over it in the Boolean True case (foreground and background).
 
Snippet.png
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

Additional Information

The colors of the transition cases (True to False and False to True) are only visible if the Boolean Control is configured as Switch or Latch when Released (See Changing the Mechanical Action of a Boolean Object).


You can set 1, 2, 4 or 6 Clusters for the states:
  • If you pass in only one Cluster, this property uses that values for FalseTrue to False, True and False to True states. Both Hover over Button states will remain in the original setting of the Control.
  • If you pass in two Clusters, this property uses the first values for the False and True to False states. Similarly, this property uses the second values for the True and False to True states. Both Hover over Button states will remain in the original setting of the Control.
  • If you pass in four Clusters, this property uses the first values for the False state, the second for the True to False state, the third for the True state and the fourth for the False to True state. Both Hover over Button states will remain in the original setting of the Control.
  • If you pass in all six Clusters, this property will use every value as described in the solution.

In previous versions of LabVIEW, the Colors[4] property used U32 numeric constants to set the RGB color value of the Boolean case by default. To set the colors of your Boolean control in this case you can:
  • Specify a color using these numeric constants using the RGB color code. Usually, this code is specified by a scale from 0-255 for each color. For example, the color red is specified by the RGB code 255, 0, 0.  To use this code, convert the RGB code numbers to hexadecimal with the form RRGGBB.  You will also need to change the format of the numeric constants in the cluster from floating-point to hexadecimal.  Using the hexadecimal RGB codes, enter FF0000 (for red) and 00FF00 (for green) into the numeric constants corresponding to the case associated with each color. In this example, the False case is red and the True case is green.
  • A much more intuitive way to specify the color is by replacing the numeric constants in the cluster with color box constants. To do this, delete the numeric constants in the cluster and place color box constants found on the All Functions » Numeric » Additional Numeric Constants palette of the block diagram. After placing these constants in the cluster, specify the color you would like to use by clicking on the color box constant.