Example Code

Change Color Numeric Control Programmatically

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabWindows/CVI

Code and Documents

Attachment

Description

Overview

This is a simple example where the color of a color numeric control changes according to the numeric value on a dial.

 

Description

This example makes use of an EVENT_COMMIT callback on a dial. We use the GetCtrlVal function to determine what value is stored in the dial. Using this and a simple 'if' statement, we use the MakeColor function to dictate what color will be displayed on the color numeric control. See the following resources for additional information:

 

https://www.ni.com/docs/en-US/bundle/labwindows-cvi/page/cvi/uiref/cvicolor_numeric_control_overview...

https://www.ni.com/docs/en-US/bundle/labwindows-cvi/page/cvi/uiref/cvimakecolor.htm

https://www.ni.com/docs/en-US/bundle/labwindows-cvi/page/cvi/uiref/cvisetctrlval.htm

 

Steps to Implement or Execute Code

  1. Unzip the NumericColorChange folder
  2. Open the NumericColorChange.prj project
  3. From within the CVI workspace, open the NumericColorChange.c file and the NumericColorChange.uir file
  4. Click the run button
  5. Scroll up and down on the dial control to view the color change.

 

Requirements

Software: CVI 2012 (or later)

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

Kelsey W.
National Instruments
Applications Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.