I have been unable to put together a bit of string rendering code that gives me everything I am aiming for. To this point, only trade-offs.
I am shooting for something that behaves the way Windows7 desktop shortcuts do, in that there is an image above text and that text can wrap once, with anything more truncated with an ellipse.
Such as:
I am using TextRenderer.DrawText
and I have tried various combinations of TextFormatFlags
, but I can only get either text that wraps indefinitely, or text that stops at a single line and has the ellipsis.
Some examples. The bounds provided to TextRenderer
are, in all cases, within the bounds of the ClipRectangle
of the surface in which I am drawing. The text it is attempting to render is "This is the rather long name of a group called #1.".
This code:
TextFormatFlags flags = TextFormatFlags.HorizontalCenter |
TextFormatFlags.NoPadding | TextFormatFlags.WordBreak |
TextFormatFlags.EndEllipsis;
Rectangle rect = new Rectangle(x, y, this.Width - 6, this.Height - y);
TextRenderer.DrawText(e.Graphics, _text, Font, rect, _textColor, flags);
...produces this:
While simply removing the TextFormatFlags.WordBreak
flag produces:
How can I do this such as I get wrapping as far as is possible within the bounds of the Rectangle
I pass, followed by an ending ellipse when truncation occurs?