我注意到,当我们尝试使用C#列出字体,它工作正常; 但是,如果我们要在应用程序运行时安装新的字体,调用字体的枚举不会返回新的字体,直到应用程序重新启动。
代码如下:
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
。
我必须在这里理解错误的东西。 我怎样才能得到上面的代码重新查询系统的字体,甚至是新的?
你尝试过吗?
using System.Drawing.Text; InstalledFontCollection fonts = new InstalledFontCollection(); foreach (FontFamily ff in fonts.Families) { if (ff.IsStyleAvailable(FontStyle.Regular)) Items.Add(ff.Name); }
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); } }