LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change font size in control dynamically if length of displayed data causes wrapping or overrun

Solved!
Go to solution

I was wondering if anyone has come up with a good method to check if a control's value doesn't fit in the control's on-screen space (when displayed).

 

For example, I may have a string control that is sized such that it will just about fit 6 characters at 36pt. Most of the possible values to display will be 6 characters or shorter, but a few may be longer - causing the text to either wrap onto a new line (and not be visible) or run out of the edge of the control (and be illegible). As I have no room to make the control bigger, I need to change the font size whenever this occurs.

 

Lazy me knows I can just check if the string is longer than 6 characters, and set the font size smaller if it is. It'd be better to find a more generic solution (as this situation can occur with any number of characters being the limit). Also, as most fonts have varying widths of character, it'd be better if there were a way to directly check if the string's value overruns or causes wrapping.

 

I can't seem to find any properties that could help me, so I'd appreciate any suggestions!

0 Kudos
Message 1 of 3
(2,725 Views)
Solution
Accepted by topic author jrveale

Hi jrveale,

 

you can use the picture drawing functions to determine the pixel size of your string (GetTextRect)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 3
(2,716 Views)

I had no idea that vi existed, thanks!

0 Kudos
Message 3 of 3
(2,696 Views)