From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I automatically word wrap a string placed in a (multicolumn) listbox ?

Hello,

Using LabView 7.0:
I need to automatically wrap text inserted in a multicolumn listbox.
The size of the listbox is fixed and I don't know the legth of the string that will be inserted. But the whole string must be visible, because it's Information is important
I'm not allowed to use a fixed width font. 😞
Has anyone any ideas (or a solution already?)
How can I compute the length of a string in pixel to calculate to position to wrap?

Thanks in advance,

best regards,

Rainer
0 Kudos
Message 1 of 12
(6,654 Views)
Hi,
To compute the sizes of text written using some font you can use "Functions->Graphics & Sound->Picture Functions->Get Text Rect.vi". In this function you can specify the font name, its size, and some options (italic, bold, etc.).

Good luck.

Oleg Chutko.
Message 2 of 12
(6,649 Views)
Thanks Oleg,

I guess that's exactly what I need.
Why didn't I find this ?? 😉

Regards

Rainer
0 Kudos
Message 3 of 12
(6,648 Views)
Hello Rainer,

I am facing the same problem.
But I could not mechanise any method to word wrap using the Get Text Rect.vi.
Would you please let me know in detail how you would solve the problem.

Veena
0 Kudos
Message 4 of 12
(6,578 Views)
Hi Veena,

The trick is to use the Get Text Rect.vi to calculate where to wrap your text string. There's no feature to automatically wrap the string for you, so you will have to split you string into sections/lines, that doesn't exceed the width of the column in the listbox.

Good luck!
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 5 of 12
(6,551 Views)
Hello Philip
Thank you for the reply.
I would do it.

Bye Bye
Veena
0 Kudos
Message 6 of 12
(6,540 Views)

Extremely late to the party here...Smiley LOL

 

I required this exact fuction.  Put this together today.  Specify the max character length and function will insert a CARRAGE RETURN at the end of each set of characters.

 

Enjoy! 

Andrew

LV2010

Download All
0 Kudos
Message 7 of 12
(5,607 Views)

This VI is an optimized version of a VI I found on here by Doug Norman.  This is a little more advanced as it resizes a control to the same width (in pixels) as the listbox, feeds the text in, lets the resized control wrap the text, then takes each line from the control and adds a return to it.  By doing it in this fashion, you wrap based on the width of the MCL and not a predetermined amount of characters.

 

Edit:

I forgot it contained a typedef.  Let me clean it up.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 12
(5,599 Views)

Here's the cleaned up version.  (The Font cluster inside the typedef is the LV typedef for the Font property on any text control - therefore, you select the cell on the MCL and take the font property from there and bundle it into this VI.  That way, this VI even takes into account the font properties - like size and style, for instance - when calculating the wrapping.)

 

Holy cow, I had to use Google Chrome just to upload a zip file...

 

 

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 12
(5,581 Views)

Word wrapping is a very interesting topic and good practice for many programming techniques.  My wrapper let's me do cool stuff like this:

 

WordWrap.png

 

Looks better when I run it through my hyphenator first, yet another interesting problem....

 

Of course for the MCL and its ilk the greedy algorithm (fancy name for the technique described in earlier posts) works just fine.

Message 10 of 12
(5,556 Views)