Programmatically Change Font, Color, or Size of String Subset in LabVIEW

Updated Dec 1, 2023

Environment

Software

  • LabVIEW

  • I can manually select a portion of the text in a string control or indicator and change its colors, but how can I do this programmatically?
  • How do I programmatically change the color, font, or formatting of a section of a string control?

You can programmatically change the font of a subset of text from a string control or indicator by following these steps:
  1. Right-Click on the string control or indicator and select Create»Property Node»Text»Selection»Start
  2. Right-click on the Text.SelStart property and select Create»Constant. This specifies the offset of the first character of the selected text.
  3. Expand the property node to expose a second property.
  4. Left-click on this second property and select Text»Selection»End
  5. Right-click on the Text.SelEnd property and select Create»Constant. This specifies the offset of the last character of the selected text. 
  6. Expand the property node to expose a third property. 
  7. Left-click on the third property and select Text»Font >> then the font property to be programmatically controlled. 
    • For example: Select Text >> Font >> Color to bring up the Text.FontColor property on the Property Node. Right-click on the property's input node to Create Constant, then left-click on the created Color Box Constant and select a color from the palette.
  8. Repeat steps 6 and 7 to programmatically control additional font characteristics for the selected text.
Note: The Text >> Font properties (like Text.FontColor and Text.FontBold) will change the formatting for only the text selection (from SelStart to SelEnd indices). The Text >> Text properties (e.g. Text.TextColor) will change formatting for all text in the string.

The snippet below provide an example of different ways you can apply these properties.

 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.


The outcome of the code above is the following formatted string control.

Additional Information