不知以下代码是否是你需要的功能:
- public int MeasureTextControlString(Selection Selection, string FormattingPrinter)
- {
- int iLength;
- using (ServerTextControl tx = new ServerTextControl())
- {
- tx.Create();
- tx.PageSize.Width = 10000;
- tx.FormattingPrinter = FormattingPrinter;
- foreach (PropertyInfo property in Selection.GetType().GetProperties())
- {
- if (property.GetValue(Selection, null).ToString() == "")
- continue;
- property.SetValue(tx.Selection, property.GetValue(Selection, null), null);
- }
- tx.SelectAll();
- return iLength = tx.TextChars[tx.Selection.Length].Bounds.Right - tx.TextChars[tx.Selection.Start + 1].Bounds.Left;
- }
- }
复制代码
http://blog.gcpowertools.com.cn/post/2012/11/16/在TextControl中测量文本长度.aspx |