码迷,mamicode.com
首页 > Windows程序 > 详细

【174】C#添加非默认字体

时间:2015-11-05 21:58:34      阅读:798      评论:0      收藏:0      [点我收藏+]

标签:

参考:C# WinForm程序安装字体或直接调用非注册字体

参考:百度知道

  在Debug文件夹下面新建一个font的文件夹,然后将字体的文件复制到里面,使用的时候,直接调用字体文件!

        private void Form1_Load(object sender, EventArgs e)
        {
            String ls_appPath = System.Windows.Forms.Application.StartupPath + "\\font\\";//font是程序

            String fontFile1 = ls_appPath + "ygyxsziti2.0.TTF";

            System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();

            pfc.AddFontFile(fontFile1);//字体文件的路径
            
            Font myFont1 = new Font(pfc.Families[0], 41, FontStyle.Regular, GraphicsUnit.Point, 0);//myFont1就是你创建的字体对象

            textBox1.Font = myFont1;
        }

实例二:

技术分享

String ls_appPath = System.Windows.Forms.Application.StartupPath + "\\font\\";//font是程序

String fontFile1 = ls_appPath + "LCDM2N__.TTF";
String fontFile2 = ls_appPath + "张海山锐线体简1.0.TTF";

System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();

pfc.AddFontFile(fontFile1);//字体文件的路径
pfc.AddFontFile(fontFile2);//字体文件的路径

Font myFont1 = new Font(pfc.Families[0], lb_hour.Font.Size);//myFont1就是你创建的字体对象
Font myFont2 = new Font(pfc.Families[1], lb_nowDate.Font.Size);//myFont1就是你创建的字体对象

lb_hour.Font = lb_mh1.Font = lb_mh2.Font = lb_minite.Font = lb_second.Font = myFont1;
lb_nowDate.Font = lb_week.Font = myFont2;

技术分享

【174】C#添加非默认字体

标签:

原文地址:http://www.cnblogs.com/alex-bn-lee/p/4940712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!