TextRenderer How to make text multi-line using ellipsis?

How can I make such a text (simple list)?

default listview render

Attempting code like this does not produce ellipses:

TextRenderer.DrawText(_listGraphics,
                   anItem.Text, GetItemFont(anItem),
                   textRec,
                   Color.FromKnownColor(KnownColor.ControlText),
                   TextFormatFlags.Top| TextFormatFlags.EndEllipsis|
                   TextFormatFlags.WordBreak | TextFormatFlags.HorizontalCenter);

if I delete TextFormatFlags.WordBreak, then the text becomes a separate line.

Its manual hot track items, while drag-n-drop above them.

+3
source share
1 answer

As Hans taught me, there is a flag for this by turning on the TextBoxControl flag:

TextRenderer.DrawText(e.Graphics, myString, this.Font,
                      textRec, Color.Black, Color.Empty,
                      TextFormatFlags.HorizontalCenter |
                      TextFormatFlags.TextBoxControl |
                      TextFormatFlags.WordBreak |
                      TextFormatFlags.EndEllipsis);
+5
source

Source: https://habr.com/ru/post/1525322/


All Articles