测量以指定宽度包装的文本高度 [英] Measure text height wrapped in a specified width
本文介绍了测量以指定宽度包装的文本高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Graphics
中找到了以下方法: code>
graphicsObj.MeasureString(text,font,width);
但它需要一个 Graphics
的实例,而当时我还没有图形实例。事实上,我更喜欢静态方法来查找高度。 TextRenderer.MeasureText(..)
可能是一个选项,但它缺少一个建议宽度的参数。 方案
过载&您需要的标志是:
var size = TextRenderer.MeasureText(text,font,new Size(width,height),TextFormatFlags。 WordBreak);
为了准确,您应该尝试使用接受设备上下文的重载之一。
How can I calculate the height needed to render a text wrapped in a specified width?
I found the following method in Graphics
graphicsObj.MeasureString(text, font, width);
But it needs an instance of Graphics
and at the time I have not graphics instance. In fact I prefer a static method to find the height. TextRenderer.MeasureText(..)
could be an option but it lacks a parameter for proposed width.
解决方案
The overload & flag you need is:
var size = TextRenderer.MeasureText(text, font, new Size(width, height), TextFormatFlags.WordBreak);
For accuracy you should really try to use one of the overloads that accepts a device context.
这篇关于测量以指定宽度包装的文本高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文