Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a label control truncate long strings with an ellipsis?

I have a label with changing text and I wish it to be a single line with fixed length. Whenever the text is longer then the label length, I want it to display whatever fits with "..." at the end. For example:

Some Very Long Text

would look like:

Some Very Lon...

Does anyone know how to do that?

like image 899
MichaelB Avatar asked Mar 11 '13 11:03

MichaelB


People also ask

How do you trim a long string?

If it's longer than a given length n , clip it to length n ( substr or slice ) and add html entity &hellip; (…) to the clipped string. function truncate( str, n, useWordBoundary ){ if (str. length <= n) { return str; } const subString = str. slice(0, n-1); // the original check return (useWordBoundary ?

What is Auto ellipsis?

Remarks. Set AutoEllipsis to true to display text that extends beyond the width of the Label in a tooltip when the user passes over the control with the mouse. If AutoSize is true , the label will grow to fit the text and an ellipsis will not appear. Important.


1 Answers

One of the options is to set Label.AutoEllipsis to true.

Set AutoEllipsis to true to display text that extends beyond the width of the Label when the user passes over the control with the mouse. If AutoSize is true, the label will grow to fit the text and an ellipsis will not appear.

So, you need to set AutoSize to false. Ellipsis appearance depends on label's fixed width. AFAIK, you need to manually handle text changes to make it depend on text length.

like image 78
default locale Avatar answered Oct 21 '22 23:10

default locale