首页 > Windows开发 > 详细

[转]将字体嵌入程序资源中 C# Winform

时间:2014-06-13 14:58:53      阅读:726      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
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 = new byte[stream.Length];

            stream.Read(fontData, 0, (int)stream.Length);
            stream.Close();

            unsafe
            {

                fixed (byte* pFontData = 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);
        }
    }
}
bubuko.com,布布扣

 

[转]将字体嵌入程序资源中 C# Winform,布布扣,bubuko.com

[转]将字体嵌入程序资源中 C# Winform

原文:http://www.cnblogs.com/z5337/p/3785131.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!