首页 > 代码库 > [转]将字体嵌入程序资源中 C# Winform
[转]将字体嵌入程序资源中 C# Winform
http://social.msdn.microsoft.com/Forums/officeapps/zh-CN/61b717ae-f925-443a-baad-2b85f2564826/cwinformsvs2010
namespace WindowsFormsApplication2 { public partial class Form1 : Form { PrivateFontCollection pfc = new PrivateFontCollection(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { string fontName = "WindowsFormsApplication2.汉仪水波体简.ttf"; Assembly assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream(fontName); byte[] fontData = http://www.mamicode.com/new byte[stream.Length]; stream.Read(fontData, 0, (int)stream.Length); stream.Close(); unsafe { fixed (byte* pFontData =http://www.mamicode.com/ fontData) { pfc.AddMemoryFont((System.IntPtr)pFontData, fontData.Length); } } } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Font font = new Font(pfc.Families[0], 20); g.DrawString("测试文字", font, new SolidBrush(Color.Black), 200, 100); } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。