Is there a combination of TextFormatFlags to allow text wrapping and an ending ellipsis?
c#, text-rendering
Solution
You have to use a, cough, unintuitively named option to get both word breaks and the end-ellipsis. `TextFormatFlags.TextBoxControl` gives you what you are looking for.
This has some additional formatting behavior, none that you are likely to be upset about if you like the way the icon title looks, it uses the same winapi function. Key thing it does is not display a clipped line, like a multi-line TextBox doesn't, also giving you the ellipsis back.
Problem
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?