有没有办法检测vb.net web应用程序中文本的实际宽度?它需要依赖于它的字体样式和大小。在vb.net中检测文本的宽度
在vb6中,您可以将文本复制到标签中,并将其展开为适合宽度,然而这不适用于vb.net。
有没有办法检测vb.net web应用程序中文本的实际宽度?它需要依赖于它的字体样式和大小。在vb.net中检测文本的宽度
在vb6中,您可以将文本复制到标签中,并将其展开为适合宽度,然而这不适用于vb.net。
更新:在进一步的检查,TextRenderer.MeasureText
似乎是一个更好的选择:
Dim text1 As String = "Measure this text"
Dim arialBold As New Font("Arial", 12.0F)
Dim textSize As Size = TextRenderer.MeasureText(text1, arialBold)
措施指定的字符串时 用指定的字体绘制。
Dim myFontBold As New Font("Microsoft Sans Serif", 10, FontStyle.Bold)
Dim StringSize As New SizeF
StringSize = e.Graphics.MeasureString("How wide is this string?", myFontBold)
标签技巧仍然有效,但它笨重和低效。 – 2011-03-09 12:57:14
它总是:-) – Urbycoz 2011-03-09 13:24:38