C# System.Drawing.Text.AddMemoryFont

jiaanv6 2012-05-24 04:45:32
想请问一下各位高手,有人会打字体封装到程序里后用System.Drawing.Text.AddMemoryFont来动用吗?

上网查了资料如:
PrivateFontCollection pfc = new PrivateFontCollection();

string NameSpc = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString();

Stream stmFont = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(NameSpc + ".AN.TTF");
if (null != stmFont)
{

byte[] rgbyt = new Byte[stmFont.Length];

stmFont.Read(rgbyt, 0, rgbyt.Length);

IntPtr pbyt = Marshal.AllocCoTaskMem(rgbyt.Length);

if (null != pbyt)
{

Marshal.Copy(rgbyt, 0, pbyt, rgbyt.Length);

pfc.AddMemoryFont(pbyt, rgbyt.Length);

Marshal.FreeCoTaskMem(pbyt);

}

}
在进行调度时,发现pfc.AddMemoryFont是添加进去,不过程序动用
Font f = new Font(pfc.Families[0], 15, FontStyle.Bold);
//设置字体
foreach (Control labb in this.Controls)
{
if (labb is Label)
{
labb.Font = f;
}
}
就是显不出结果

如果用pfc.AddFontFile("AN.TTF");就可以正常显示

不知何解,请高手指点指点。。。。。

先说声谢谢
...全文
111 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiaanv6 2012-05-24
  • 打赏
  • 举报
回复
效果出现了不过SetCompatibleTextRenderingDefault 设为true后,只要一出异常,程序就不能运行了。。。。。。。怎样解决。????
cnfixit
jiaanv6 2012-05-24
  • 打赏
  • 举报
回复

cnfixit
谢谢
cnfixit 2012-05-24
  • 打赏
  • 举报
回复
要使用内存字体,必须使用 GDI+ 呈现控件上的文本。使用可传递 true 的 SetCompatibleTextRenderingDefault 方法来设置应用程序上的 GDI+ 呈现,或者通过将控件的 UseCompatibleTextRendering 属性设置为 true 来设置各个控件上的 GDI+ 呈现。有些控件无法使用 GDI+ 来呈现。


UseCompatibleTextRendering 你试了么?

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧