检测vb.net中文本的宽度 [英] Detect width of text in vb.net

查看:30
本文介绍了检测vb.net中文本的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检测 vb.net 网络应用中文本的实际宽度?它需要依赖于它的字体样式和大小.

Is there a way to detect the actual width of text in a vb.net web app? It needs to be dependant upon its font-style and size.

在 vb6 中,您可以将文本复制到标签中并使其展开以适应然后测量其宽度,但这在 vb.net 中不起作用.

In vb6 you could copy the text into a label and make it expand to fit then measure its width, but this won't work in vb.net.

推荐答案

更新:进一步检查,TextRenderer.MeasureText 似乎是一个更好的选择:

Update: On further inspection, TextRenderer.MeasureText seems a better option:

    Dim text1 As String = "Measure this text"
    Dim arialBold As New Font("Arial", 12.0F)
    Dim textSize As Size = TextRenderer.MeasureText(text1, arialBold)

参见 图形.MeasureString:

测量指定的字符串时用指定的字体绘制.

Measures the specified string when drawn with the specified Font.

    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)

这篇关于检测vb.net中文本的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆