根据字体大小得到字符串显示时的宽度(C#)
字符串的宽度自适应容器 Graphics g = Graphics.FromImage(new Bitmap(1, 1)); SizeF size = g.MeasureString(lblTitle.Text, new Font("宋体", 24 * 0.0625F, FontStyle.Bold)); float oldSize=(800*0.0625F);//1px=0.0625em
·
字符串的宽度自适应容器
Graphics g
=
Graphics.FromImage(
new
Bitmap(
1
,
1
));
SizeF size = g.MeasureString(lblTitle.Text, new Font( " 宋体 " , 24 * 0.0625F , FontStyle.Bold));
float oldSize = ( 800 * 0.0625F ); // 1px=0.0625em
float newSize = ( 0.75F / size.Width ) * oldSize;
SizeF size = g.MeasureString(lblTitle.Text, new Font( " 宋体 " , 24 * 0.0625F , FontStyle.Bold));
float oldSize = ( 800 * 0.0625F ); // 1px=0.0625em
float newSize = ( 0.75F / size.Width ) * oldSize;
size.Width 的单位是em
更多推荐
已为社区贡献1条内容
所有评论(0)