【发布时间】:2018-10-29 07:50:14
【问题描述】:
我无法确定是否在一组机器上安装了自定义字体(欧几里德三角形)。
我使用了此处列出的代码 “Test if a Font is installed”,它适用于我的 Windows 10 机器。但它不适用于 Windows 7 机器和我客户的一堆机器。
所有机器都有 .Net 4.5 及更高版本。
如果我尝试列出机器上的所有字体,则字体未列出:
static void ListFonts()
{
try
{
using (InstalledFontCollection fontsCollection = new InstalledFontCollection())
{
FontFamily[] fontFamilies = fontsCollection.Families;
var fonts = new List<string>();
foreach (FontFamily font in fontFamilies)
fonts.Add(font.Name);
var file = new FileInfo(Assembly.GetExecutingAssembly().Path() + "\\fonts.txt");
Serializer.SerializeToFile(fonts, file.FullName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Printer Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error);
var file = new FileInfo(Assembly.GetExecutingAssembly().Path() + "\\log.txt");
File.WriteAllText(file.FullName, ex.ToString());
Console.WriteLine(ex.ToString());
}
}
编辑:我已以管理员身份运行我的代码,以确认问题与权限无关。
【问题讨论】:
-
只是猜测:其他机器权限不足?
-
您的代码不会搜索特定字体,它只会将它们添加到列表中,然后将其写入文件……
-
我知道我列出的代码不会搜索特定字体。我链接到的帖子包含大量示例 - 我已经尝试了所有这些,但在目标机器上都没有。
-
因此,如果我正确阅读了您编辑的帖子,您说字体已安装(即可以从写字板使用)但在您使用代码列出字体时不显示?
-
正确。该字体出现在 MS Word 等中并且可以使用。通过代码列出字体时找不到字体。