Example Code

Auto-size to Text (Horizontal) for Strings and Paths

Code and Documents

Attachment

Download All

     I recently started putting String Indicators on some of my programs that identified the Routine, along with its Version Number.  In addition, several of these routines also displayed File and Folder paths. As the first image shows, if the String or Path Indicator is too short to contain the entire String or Path, the displayed data will be truncated, sometimes without a clear indication that information isn't being shown.  One alternative that I initially adopted was to simply make the String and Path Indicators much too wide and accept blank spaces at the end.  However, a preferred solution would be to adjust the String and Path Indicators programmatically so they fit whatever contents had been placed in them (as shown in the second image).

     The Zip file attached contains a 7-page PDF description of my adventures in tackling this problem, including my attempt to add this as an Idea on the Idea Exchange, two versions of code that accomplish this, plus a set of test routines showing resizing of both Strings and Paths for text of varying size, boldness, and (just for fun) color.  In addition, this code works for Silver, Modern, Classic, and (with a caveat) System controls.

Strings_and_Paths_2.png

Strings_and_Paths.png

Bob Schor

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

Comments
J-M
Active Participant
Active Participant
on

Great and it seems to work with unicode string!

Bob_Schor
Knight of NI Knight of NI
Knight of NI
on

Thanks -- I didn't think to test for that!

BS

J-M
Active Participant
Active Participant
on

The only small modification I have done is in "UTIL Initialize String Size.vi".  I divide by two if it is an unicode string (to limit the number of iterations).

UTIL Initialize String Size.png

I currently use your library in a "XControl - Unicode Ring Text":

http://forums.ni.com/t5/LabVIEW/XControl-Unicode-Ring-Text-some-questions/m-p/3203234#M929009

HunterSeeker
Member
Member
on

BTW, there is a much better automatic way todo this that does not invovle calling property nodes in a loop and hammering the UI thread. Just write the string into the caption of a empty transparent string. If the caption is set to size to text it will automagically size the string as it changes. Use a classic flat string so you can set it to be transparent and make sure the value is initilized empty.String_Resizer.png

There are 2 small pitfalls to this method, 1 you have to write into the property node so there is still some UI thread cost if you are writing to the string regularly in a loop compared to writing into a terminal, and 2: you can only use simple string formatting like background color and not for instance the puffy silver box.

-Hunter

Contributors