How can I convert a System.Drawing.font to a System.Windows.Media.Fonts or TypeFace?

后端 未结 2 888
有刺的猬
有刺的猬 2021-01-02 00:55

How can I convert a System.Drawing.Font to a System.Windows.Media.Fonts or TypeFace?

Or how can I generate an instance of

2条回答
  •  滥情空心
    2021-01-02 01:24

    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();
    

提交回复
热议问题