在使用.NET之前,确保字体存在的方法如下:
using System.Drawing;
using System.Drawing.Text;
// 设置字体列表
List<FontFamily> fontFamilies = new List<FontFamily>();
fontFamilies.Add(new FontFamily("Arial"));
fontFamilies.Add(new FontFamily("Calibri"));
using Microsoft.Win32;
// 更改注册表项以显示特殊字体
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.Write);
key.SetValue("arial.gdi", "TrueType", RegistryValueKind.String, RegistryKeys.ControlPanelDisplay);
key.SetValue("calibri.gdi", "TrueType", RegistryValueKind.String, RegistryKeys.ControlPanelDisplay);
key.SetValue("arialbd.gdi", "TrueType", RegistryValueKind.String, RegistryKeys.ControlPanelFont);
key.SetValue("wingdings.gdi", "TrueType", RegistryValueKind.String, RegistryKeys.ControlPanelFont);
key.SetValue("times.ttf", "TrueType", RegistryValueKind.String, RegistryKeys.ControlPanelFont);
key.SetValue("timesbn.ttf", "TrueType", RegistryValueKind.String, RegistryKeys.ControlPanelFont);
通过这种确保字体存在的各种方法,可以提高应用程序的灵活性和稳定性。
领取专属 10元无门槛券
手把手带您无忧上云