到最后还是要我自己结贴,通过一个朋友的帮忙踩解决这个问题,将资源内嵌到程序中,然后去获取这种字体即可,代码如下: private Font GetSpecialFont() { int size = 20; Font fnt = null; if (null == m_pfc) { string NameSpc = Assembly.GetExecutingAssembly().GetName().Name.ToString(); // First load the font as a memory stream Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream( NameSpc + ".标准楷体简.ttf"); if (null != stmFont) { // // GDI+ wants a pointer to memory, GDI wants the memory. // We will make them both happy. // // First read the font into a buffer byte[] rgbyt = new Byte[stmFont.Length]; stmFont.Read(rgbyt, 0, rgbyt.Length); // Then do the unmanaged font (Windows 2000 and later) // The reason this works is that GDI+ will create a font object for // controls like the RichTextBox and this call will make sure that GDI // recognizes the font name, later. //uint cFonts; //AddFontMemResourceEx(rgbyt, rgbyt.Length, IntPtr.Zero, out cFonts); // Now do the managed font IntPtr pbyt = Marshal.AllocCoTaskMem(rgbyt.Length); if (null != pbyt) { Marshal.Copy(rgbyt, 0, pbyt, rgbyt.Length); m_pfc = new PrivateFontCollection(); m_pfc.AddMemoryFont(pbyt, rgbyt.Length); Marshal.FreeCoTaskMem(pbyt); } } } if (m_pfc.Families.Length > 0) { // Handy how one of the Font constructors takes a // FontFamily object, huh? :-) fnt = new Font(m_pfc.Families[0], size); } return fnt; }
private Font GetSpecialFont()
{
int size = 20;
Font fnt = null; if (null == m_pfc)
{
string NameSpc = Assembly.GetExecutingAssembly().GetName().Name.ToString();
// First load the font as a memory stream
Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream(
NameSpc + ".标准楷体简.ttf"); if (null != stmFont)
{ //
// GDI+ wants a pointer to memory, GDI wants the memory.
// We will make them both happy.
// // First read the font into a buffer
byte[] rgbyt = new Byte[stmFont.Length];
stmFont.Read(rgbyt, 0, rgbyt.Length); // Then do the unmanaged font (Windows 2000 and later)
// The reason this works is that GDI+ will create a font object for
// controls like the RichTextBox and this call will make sure that GDI
// recognizes the font name, later.
//uint cFonts;
//AddFontMemResourceEx(rgbyt, rgbyt.Length, IntPtr.Zero, out cFonts); // Now do the managed font
IntPtr pbyt = Marshal.AllocCoTaskMem(rgbyt.Length);
if (null != pbyt)
{
Marshal.Copy(rgbyt, 0, pbyt, rgbyt.Length);
m_pfc = new PrivateFontCollection();
m_pfc.AddMemoryFont(pbyt, rgbyt.Length);
Marshal.FreeCoTaskMem(pbyt);
}
}
} if (m_pfc.Families.Length > 0)
{
// Handy how one of the Font constructors takes a
// FontFamily object, huh? :-)
fnt = new Font(m_pfc.Families[0], size);
} return fnt;
}