如何在WPF中测量字符串Hight/Width [英] How yo measure a string Hight/Width in WPF

查看:437
本文介绍了如何在WPF中测量字符串Hight/Width的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何在WPF中测量字符串大小..在C1PdfDocument(component1PDF)中具有一个功能MeasureString(string,Font)以测量字符串的宽度/高度,WPF具有类似的功能.


How to measure the string size in WPF..In C1PdfDocument(component1PDF)have a function MeasureString(string,Font) to measure width/height of string do WPF has similar function.

internal float GetWidth(string text,Font font) {
     C1PdfDocument pdf;
     return pdf.MeasureString(text,font).Width;
   }


问候,
sajith


Regards,
sajith

推荐答案

使用类System.Windows.Media.FormattedText完成此操作,请参见: http://stackoverflow.com/questions/824281/wpf-等效于textrenderer [ ^ ].

—SA
This is done using the class System.Windows.Media.FormattedText, please see: http://msdn.microsoft.com/en-us/library/system.windows.media.formattedtext.aspx[^].

Also, see the code sample in this discussion: http://stackoverflow.com/questions/824281/wpf-equivalent-to-textrenderer[^].

—SA


这篇关于如何在WPF中测量字符串Hight/Width的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆