找回密码
 立即注册

QQ登录

只需一步,快速开始

ZenosZeng 讲师达人认证 悬赏达人认证
超级版主   /  发表于:2013-9-16 17:18  /   查看:4311  /  回复:1
如题,怎么计算txtcontro中文字长度。

1 个回复

倒序浏览
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2013-9-16 17:20:00
沙发
不知以下代码是否是你需要的功能:
  1.     public int MeasureTextControlString(Selection Selection, string FormattingPrinter)
  2.     {
  3.         int iLength;
  4.         using (ServerTextControl tx = new ServerTextControl())
  5.         {
  6.             tx.Create();
  7.             tx.PageSize.Width = 10000;
  8.             tx.FormattingPrinter = FormattingPrinter;
  9.             foreach (PropertyInfo property in Selection.GetType().GetProperties())
  10.             {
  11.                 if (property.GetValue(Selection, null).ToString() == "")
  12.                     continue;
  13.                 property.SetValue(tx.Selection, property.GetValue(Selection, null), null);
  14.             }
  15.             tx.SelectAll();
  16.             return iLength = tx.TextChars[tx.Selection.Length].Bounds.Right - tx.TextChars[tx.Selection.Start + 1].Bounds.Left;
  17.         }
  18.     }
复制代码



http://blog.gcpowertools.com.cn/post/2012/11/16/在TextControl中测量文本长度.aspx
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部