C#的FontFamily没有显示新字体 [英] C# FontFamily not showing new fonts

查看:1531
本文介绍了C#的FontFamily没有显示新字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我们试图使用C#列出字体,它的工作正常;但是,如果我们要在应用程序运行时安装新的字体,调用字体的枚举不会返回新字体,直到应用程序重新启动。

I notice that when we are trying to list fonts using C#, that it works fine; however, if we are to install a new font while the application is running, calling the enumeration of fonts doesn't return the new font, until the application is restarted.

代码如下:

public void Populate(bool b)
{
    both = b;
    foreach (FontFamily ff in FontFamily.Families)
    {
        if(ff.IsStyleAvailable(FontStyle.Regular))
            Items.Add(ff.Name);                                             
    }           
}

上述方法的注意事项:
Items.Add()正在向 comboBox 添加项目。

Notes for the above method: Items.Add() is adding items to a comboBox.

我必须在这里理解错误。

I must be understanding something incorrectly here. How can i get the above code to requery the system for the fonts, even the new ones?

推荐答案

您尝试使用

using System.Drawing.Text;
InstalledFontCollection fonts = new InstalledFontCollection();
foreach (FontFamily ff in fonts.Families)
{
    if (ff.IsStyleAvailable(FontStyle.Regular))
        Items.Add(ff.Name);
}

这篇关于C#的FontFamily没有显示新字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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