在WPF中,在System.Windows.Media命名空间
MSDN FormattedText中有FormattedText,我可以这样使用:
private static Size GetTextSize(string txt,string font,int size,bool isBold) { Typeface tf = new Typeface(new System.Windows.Media.FontFamily(font),FontStyles.normal,(isBold) ? FontWeights.Bold : FontWeights.normal,FontStretches.normal); FormattedText ft = new FormattedText(txt,new CultureInfo("en-us"),System.Windows.FlowDirection.LeftToRight,tf,(double)size,System.Windows.Media.Brushes.Black,null,textformattingMode.display); return new Size { Width = ft.WidthIncludingTrailingWhitespace,Height = ft.Height }; }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。