已将 TrueType 字体添加到我的项目资源(“MyFontResource”)中,并将构建操作设置为“资源”。我的意图是用这个资源替换 Label 对象上的字体。
这是我的代码:
PrivateFontCollection myFonts = new PrivateFontCollection();
unsafe {
fixed (byte* fontBytes = Properties.Resources.MyFontResource)
myFonts.AddMemoryFont((IntPtr)fontBytes, Properties.Resources.MyFontResource.Length);
}
myLabel.Font = new Font(myFonts.Families[0], 10f);
只有当我在本地安装了字体时,字体才会按预期显示。如果我没有安装字体,那么我会在我的 C# 项目中看到最初分配给 myLabel 的字体。
怎么办?