alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

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

参考: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;
复制代码

posted on   McDelfino  阅读(753)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示