问题
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