我如何使用 C# Windows 窗体应用程序以编程方式在用户的 PC 上安装新字体,以便我可以在该应用程序包含的报告中使用该字体?
请您参考如下方法:
您可以尝试在 AddFontResource
[DllImport("gdi32.dll", EntryPoint="AddFontResourceW", SetLastError=true)]
public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)]
string lpFileName);
代码
//Install the font.
result = AddFontResource(@"C:\MY_FONT_LOCATION\MY_NEW_FONT.TTF");
error = Marshal.GetLastWin32Error();
if (error != 0)
{
Console.WriteLine(new Win32Exception(error).Message);
}
else
{
Console.WriteLine((result == 0) ? "Font is already installed." :
"Font installed successfully.");
}
