using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace Rs.Controls { public class IconFontHelper { public static System.Drawing.Text.PrivateFontCollection PFCC { get { return pfcc ?? LoadFont(); } } //提供一个字体系列集合,该集合是基于客户端应用程序提供的字体文件生成的。 private static System.Drawing.Text.PrivateFontCollection pfcc; private static System.Drawing.Text.PrivateFontCollection LoadFont() { pfcc = new System.Drawing.Text.PrivateFontCollection(); byte[] fontData = Properties.Resources.iconfont;//添加到资源里面的字体库文件 IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(fontData, 0); pfcc.AddMemoryFont(ptr, fontData.Length); //unsafe //{ // fixed (byte* pFontData = fontData) // { // pfcc.AddMemoryFont((IntPtr)pFontData, fontData.Length); // } //} return pfcc; } } }