user674311
user674311

Reputation:

C# FontFamily not showing new fonts

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?

Upvotes: 4

Views: 3561

Answers (2)

Marco
Marco

Reputation: 57573

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

Upvotes: 2

ojlovecd
ojlovecd

Reputation: 4892

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

}

Upvotes: 1

Related Questions