How do I get all installed fixed-width fonts?

后端 未结 3 2031
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 11:33

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 acce

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 11:59

    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......
            }
        }
    }
    

提交回复
热议问题