Example Code

Edit and Insert New Line in Label Text Programmatically Using LabWindows

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

  • Other

Code and Documents

Attachment

Overview

If you need to change the text of a command button, text message, or other label at run time, you can use the SetCtrlAttribute function.  If you need multiple lines in the text, use the special character "\n" to insert a new line, such as in the following line: 

SetCtrlAttribute (panelHandle, PANEL_INSERT, ATTR_LABEL_TEXT, "Press\nthis\nbutton");

 

Description

This example demonstrates how to change the label of a command using a callback function. The SetCtrlAttribute function allows the user to edit many different properties, but in this example the Label Text property is selected. Clicking the button toggles the label from one line to three.

 

button line fp.png

 

Requirements

Software

LabWindows/CVI

 

Steps to Implement or Execute Code

  1. Download and unzip the example program.
  2. Open createLine.prj.
  3. Run the program and click on Press this button.
  4. Note the new lines that are inserted in the button label text.
  5. Press the button again and note that the new lines are gone.
  6. Inspect the insertLine callback to see the SetCtrlAttribute function.

 

Additional Information or References

For more information on new lines in text, see the KnowledgeBase article How Can I Create Multiple Lines in CVI Command Buttons?

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

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