Label at the end of the client rectangle

This currently applies to WPF, but I also need an answer for WinForms, if possible.

I created a user control containing a .NET label.

The problem is this: When the label is long enough, it skips the end of the user control size, which is not elegant and can erroneously make the user think that the line is ending.

What I want to do, but don’t know how:

Check where the label gets cut off from the size of the client, and then replace the last 3 characters from there with the three dots "...". (so that the user can know that the line does not end, etc.)

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

+3
source share
1 answer

In Winforms: set the AutoSize property on the shortcut to false, and the AutoElipses property to true.

In WPF, you can set content in a TextBlock using the TextTrimming property set:

<Label Height="29"  Width="35" >
    <TextBlock TextTrimming="CharacterEllipsis">This is a really long string</TextBlock>
</Label>
+4
source

All Articles