C# AddFontFile错误:找不到文件
我跟踪了我的项目,但由于文件未找到错误而未能启动C# AddFontFile错误:找不到文件,c#,visual-studio,visual-studio-2012,C#,Visual Studio,Visual Studio 2012,我跟踪了我的项目,但由于文件未找到错误而未能启动 A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll Additional information: File not found. 这是我的密码: PrivateFontCollection modernFont = new PrivateFontCollection(); m
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
Additional information: File not found.
这是我的密码:
PrivateFontCollection modernFont = new PrivateFontCollection();
modernFont.AddFontFile("digital.ttf");
label5.Font = new Font(modernFont.Families[0], 40);
字体文件位于名称空间目录中,文件路径是否有问题?它并没有在名称空间中查找字体。它在执行目录中查找。将字体放在bin/debug文件夹中,它就会工作。我想你必须将字体文件放在可执行文件路径的目录中。@EpicKip我明白了,它现在工作了,但我想实现的是将字体包含在可执行文件中,有可能吗?@HelenClayton有可能,但我不确定如何操作。为此,您必须将字体文件添加到资源文件中,然后将其添加到exe。它不会在命名空间中查找字体。它在执行目录中查找。将字体放在bin/debug文件夹中,它就会工作。我想你必须将字体文件放在可执行文件路径的目录中。@EpicKip我明白了,它现在工作了,但我想实现的是将字体包含在可执行文件中,有可能做到吗?@HelenClayton有可能,但我不确定如何做到。为此,您必须将字体文件添加到资源文件,然后将其添加到exe。