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?
If it's longer than a given length n , clip it to length n ( substr or slice ) and add html entity … (…) 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 ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With