Why is TextRenderer.MeasureText working correctly?

I want to measure the height of text with a specific width of available canvas. The text I am transmitting is really long and I know that it will be completed. To this end, I invoke the following:

using System.Windows.Forms;
...
string text = "Really really long text that is sure to wrap...";
Font font = new Font("Arial", 14);
Size canvas = new Size(1100, 850);
Size size = TextRenderer.MeasureText(text, font, canvas);

No matter what I pass for the canvas, it always returns 14 for size.Height.

Did I miss something simple?

+5
source share
1 answer

Please use the TextFormatFlags parameter as shown below:

Size size = TextRenderer.MeasureText(text, font, canvas, TextFormatFlags.WordBreak);
+5
source

All Articles