从资源中添加字体文件 [英] addFontFile from Resources
本文介绍了从资源中添加字体文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码添加了自定义字体:
I have added a custom font using below code:
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile("C:\Path To\YourFont.ttf");
label1.Font = new System.Drawing.Font(pfc.Families[0], 16, FontStyle.Regular);
我在资源中添加了字体文件.如何使用 addFontFile
从资源中添加?
I added the font file in resources. How do I add with addFontFile
from resources?
推荐答案
如果你在资源中包含了你的字体
If you included your font in the resources
试试这个功能
private void AddFontFromMemory()
{
Stream fontStream = this.GetType().Assembly.GetManifestResourceStream("yourfont.ttf");
byte[] fontdata = new byte[fontStream.Length];
fontStream.Read(fontdata,0,(int)fontStream.Length);
fontStream.Close();
unsafe
{
fixed(byte * pFontData = fontdata)
{
pfc.AddMemoryFont((System.IntPtr)pFontData,fontdata.Length);
}
}
}
已编辑
如何从程序集中加载资源:(YourNamespace.file.ttf)
How load resource from assembly:(YourNamespace.file.ttf)
Stream fontStream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("WindowsFormsApplication1.SBADR.TTF");
我的解决方案浏览器:
这篇关于从资源中添加字体文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文