码迷,mamicode.com
首页 > 其他好文 > 详细

获取文字长度

时间:2014-08-27 18:08:58      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:winform   os   io   for   ar   cti   sp   on   new   

wpf

//获取文字长度
private double MeasureTextWidth(string text, double fontSize, string fontFamily)
{
FormattedText formattedText = new FormattedText(
text,
System.Globalization.CultureInfo.InvariantCulture,
FlowDirection.LeftToRight,
new Typeface(fontFamily.ToString()),
fontSize,
Brushes.Black
);
return formattedText.WidthIncludingTrailingWhitespace;
}

 

winform

    System.Drawing.Size fontSize = System.Windows.Forms.TextRenderer.MeasureText(value, new System.Drawing.Font("Arial", (float)btnDisplay.FontSize));

获取文字长度

标签:winform   os   io   for   ar   cti   sp   on   new   

原文地址:http://www.cnblogs.com/metoer/p/3939774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!