Setting Label's Height to adjust to text

walterf25

Expert
Licensed User
Longtime User
Hi everybody, hope everyone is having a great day, i was wondering if i could get some help, i was wondering if it's possible to adjust the height of a label so that it adjusts to the loaded text automatically, i'm loading the text from a database into labels, but some records are longer than others and i'm using a scrollview but i would like to set the label's height automatically to adjust to the loaded text, anyone knows how to do this, is it possible to do it like that?

Please anyone
:sign0163:
 

joseluis

Active Member
Licensed User
Longtime User
Right off the bat I can think of two possibilities, and involves creating a sub for the calculations:

a) If you use a fixed-width font calculate how many rows will be necessary according to the width of the view and the size of the font. If the text contains newlines, then you must sum a row for every CR there is. Word wrapping is another thing to take into account.

b) The same as before, but for non-fixed-width fonts either you use either the average character width (perhaps a little more) or a Map container for each character as a key, and its relative width as the value, for the calculations.

I don't know if there's an easier way to do it.
 
Last edited:
Upvote 0
Top