我怎么能转换System.Drawing.font到System.Windows.Media.Fonts或字体? [英] How can I convert a System.Drawing.font to a System.Windows.Media.Fonts or TypeFace?
本文介绍了我怎么能转换System.Drawing.font到System.Windows.Media.Fonts或字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能转换 System.Drawing.Font
到 System.Windows.Media.Fonts
或字体
?
或者我怎么能生成 System.Windows.Media.Fonts的一个实例
或字体
从实例 System.Drawing.Font
?
Or how can I generate an instance of System.Windows.Media.Fonts
or TypeFace
from an instance of System.Drawing.Font
?
推荐答案
你不能实例化的 Media.Fonts ,但我认为你可以得到一个 Media.FontFamily 这是我做到了这一点。
you cant instantiate Media.Fonts , but I think you can get a Media.FontFamily this is how I achieved it.
using System.Drawing;
using Media = System.Windows.Media;
Font font = new Font(new System.Drawing.FontFamily("Comic Sans MS"), 10);
//option 1
Media.FontFamily mfont = new Media.FontFamily(font.Name);
//option 2 does the same thing
Media.FontFamilyConverter conv = new Media.FontFamilyConverter();
Media.FontFamily mfont1 = conv.ConvertFromString(font.Name) as Media.FontFamily;
//option 3
Media.FontFamily mfont2 = Media.Fonts.SystemFontFamilies.Where(x => x.Source == font.Name).FirstOrDefault();
这篇关于我怎么能转换System.Drawing.font到System.Windows.Media.Fonts或字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文