我如何获得所有已安装的固定宽度字体? [英] How do I get all installed fixed-width fonts?

查看:508
本文介绍了我如何获得所有已安装的固定宽度字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有任何简单的方法来获取所有固定宽度的列表的用户的系统中安装在C#(等宽)字体?

我使用.net 3.5所以有机会获得WPF System.Windows.Media命名空间和LINQ to获取字体信息,但我不知道我要找的。

我希望能够提供宽字体的过滤列表和/或从字体的大名单挑选出等宽字体(如在VS选项对话框中看到)。


解决方案

有一个看看:

<一个href=\"http://www.pinvoke.net/default.aspx/Structures/LOGFONT.html\">http://www.pinvoke.net/default.aspx/Structures/LOGFONT.html

使用在那里的建筑物之一,然后遍历家庭,实例化一个字体,并获得了LOGFONT值和检查lfPitchAndFamily。

以下code被写入动态的和未经考验的事,但像下面应该工作:

 的foreach(FF的FontFamily在System.Drawing.FontFamily.Families)
{
    如果(ff.IsStyleAvailable(FontStyle.Regular))
    {
        字体的字体=新Font(FF,10);
        LOGFONT LF =新LOGFONT();
        font.ToLogFont(LF);
        如果(lf.lfPitchAndFamily ^ 1)
        {
            做的东西这里......
        }
    }
}

I'm wondering if there are any simple ways to get a list of all fixed-width (monospaced) fonts installed on a user's system in C#?

I'm using .net 3.5 so have access to the WPF System.Windows.Media namespace and LINQ to get font information, but I'm not sure what I'm looking for.

I want to be able to provide a filtered list of monospaced fonts and/or pick out monospaced fonts from a larger list of fonts (as seen in the VS options dialog).

解决方案

Have a look at:

http://www.pinvoke.net/default.aspx/Structures/LOGFONT.html

Use one of the structures in there, then loop over families, instantiating a Font, and getting the LogFont value and checking lfPitchAndFamily.

The following code is written on the fly and untested, but something like the following should work:

foreach (FontFamily ff in System.Drawing.FontFamily.Families)
{
    if (ff.IsStyleAvailable(FontStyle.Regular))
    {
        Font font = new Font(ff, 10);
        LOGFONT lf = new LOGFONT();
        font.ToLogFont(lf);
        if (lf.lfPitchAndFamily ^ 1)
        {
            do stuff here......
        }
    }
}

这篇关于我如何获得所有已安装的固定宽度字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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