2

我正在使用一个函数来调用要在一个区域内呈现的一段文本。该功能的基本工作是:

Dim measureSize as Size
Do
    myFont = new Font(myFont.Name, myFont.Size - 1, FontStyle.Regular, GraphicsUnit.Document)
    'Initial font size is set insanely high for the moment, during testing.
    'Low initial font size is not the problem.
    measureSize = g.MeasureString(myString, myFont)
Loop until (measuredSize.width < desiredSize.width AND measuredSize.height < desiredSize.height)

这样做的问题是 MeasureString 在它正在绘制的字符串周围添加了很多空白,并且最终的字体被渲染得太小了。

我确定我记得一些参数可以用来从 MeasureString 方法中删除所有填充,但是我的搜索目前没有出现任何结果。

有谁知道如何使用 MeasureString 来测量字符串的精确大小而没有任何边界?

4

2 回答 2

6

传给. StringFormat.GenericTypographic_ MeasureString我建议不要使用 TextRenderer,因为它在渲染到内存位图时会出现 clear-type 问题。

使用 TextRenderer 进行测量,使用 DrawString 进行绘图,无疑迟早会让你陷入不一致的境地。

于 2009-10-16T16:48:47.647 回答
0

您应该尝试使用TextRenderer.MeasureText,因为它返回文本的大小,而不是抗锯齿的文本大小。

MSDN 文章

于 2009-04-28T14:53:21.083 回答