Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know if a TLabel word wrapped the text?

I create a TLabel and add text to it dynamically, and that works just fine. But I need to know if the label word-wrapped the text because it was too large for the label's width, or if there was no need to it to wrap because the text was shorter than the label's width.

I don't mean to know whether the label's WordWrap property is set to true or false, I want to know if it wrapped the text or it didn’t.

The TLabel has the AutoSize and WordWrap properties set to true, in case that matters.

like image 751
Hiram Avatar asked Oct 23 '25 15:10

Hiram


1 Answers

You can check the label's height to find out if it is a one liner or not.

if Label1.Height = Label1.Canvas.TextHeight('.') then
  // no word wrapped

That is because:

When WordWrap is True, the width of the label is fixed. If AutoSize is also True, changes to the text cause the label to change in height.

like image 148
Sertac Akyuz Avatar answered Oct 26 '25 05:10

Sertac Akyuz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!