如何以像素为单位获取字符串长度? [英] How to get string length in pixels?

查看:121
本文介绍了如何以像素为单位获取字符串长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要一些ui布局操作。这可能吗?怎么样?请帮忙。

编辑:如果我知道文字大小。

Need for some ui layout manipulations. Is this possible and how? Please help.
If I know text size.

推荐答案

你看错了方向。就其性质而言,字符串的长度不是像素或类似的长度。字符串是完全从它们呈现方式中抽象出来的数据结构,例如字体,颜色,渲染样式,几何尺寸等。这些都是某些UI元素的一些属性,无论它们是什么。



-SA
You are looking in wrong direction. By their nature, strings do not have lengths in in pixels or something like that. Strings are data structures totally abstracted from the way they are presented, such as fonts, colors, rendering styles, geometrical sizes, etc. Those are all some properties of some UI elements, whatever they are.

—SA


string sta =嗨这是Word;

字体arialBold = new字体(Garamond,11.5F);

大小st1 = TextRenderer.MeasureText(sta,arialBold);

float pixcel = st1.Width;
string sta = "Hi This is Word";
Font arialBold = new Font("Garamond", 11.5F);
Size st1 = TextRenderer.MeasureText(sta, arialBold);
float pixcel = st1.Width;


这篇关于如何以像素为单位获取字符串长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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