Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label cuts-off at the end of the client's rectangle

Tags:

c#

This currently goes for WPF, but I need an answer for WinForms aswell, if possible.

I made a user-control that contains a .NET's Label.

The issue is: When the label is long enough, it passes the end of the user-control's size which isn't elegant and can mistake the user to think that the string ends.

What I want to do about it, but don't know how:

Check where the label is getting cut-off from the client's size, then replace the 3 last characters from there with 3 dots "...". (so the user could know that the string didn't end, etc.)

Any suggestions? (just in case: I don't mind making my own user control just for the label). Thanks.

like image 377
MasterMastic Avatar asked Dec 11 '25 12:12

MasterMastic


1 Answers

In Winforms: Set the AutoSize property on the label to false and the AutoElipses property to true.

In WPF, you can set the content to a TextBlock with the TextTrimming property set:

<Label Height="29"  Width="35" >
    <TextBlock TextTrimming="CharacterEllipsis">This is a really long string</TextBlock>
</Label>
like image 168
John Koerner Avatar answered Dec 14 '25 00:12

John Koerner



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!