C# FontFamily not showing new fonts

久未见 提交于 2019-12-23 16:27:41

问题


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.

Here's the code:

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

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?


回答1:


Did you try with

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



回答2:


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

}


来源:https://stackoverflow.com/questions/7910490/c-sharp-fontfamily-not-showing-new-fonts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!