摘要:安裝字型 c#
using System;
using System.Runtime.InteropServices;
namespace InstallMyFontExample
{
class Program {
[DllImport("gdi32", EntryPoint = "AddFontResource")]
public static extern int AddFontResourceA(string lpFileName);
[DllImport("gdi32", EntryPoint = "RemoveFontResource")]
public static extern int RemoveFontResourceA(string lpFileName);
static void Main(string[] args)
{
int result = -1; result = RemoveFontResourceA(@"C:\MY_FONT_LOCATION\MY_NEW_FONT.TTF");
Console.WriteLine((result == 0) ? "Font was not found." : "Font removed successfully.");
result = AddFontResourceA(@"C:\MY_FONT_LOCATION\MY_NEW_FONT.TTF");
Console.WriteLine((result == 0) ? "Font is already installed." : "Font installed successfully."); Console.ReadKey();
}
}
}