1.程序字体引用

2.代码Demo部分
private void LoadCustomFont()
{
// 创建一个 PrivateFontCollection 对象
PrivateFontCollection pfc = new PrivateFontCollection();
// 获取字体文件的路径(假设字体文件放在项目的 Fonts 文件夹下)
string fontPath = Application.StartupPath + "\\Resources\\Source Han Sans CN Normal.otf"; // 替换为实际路径
// 将字体文件加载到 PrivateFontCollection 中
pfc.AddFontFile(fontPath);
// 获取加载的字体(可以指定字体的索引,通常是0)
Font customFont = new Font(pfc.Families[0], 12); // 设置字体大小为 12
// 设置控件的字体为自定义字体
this.Font = customFont; // 设置整个窗体的字体
label1.Font = customFont; // 设置某个标签的字体
label1.Text = "测试使用";
label2.Text = "测试使用";
}
3.运行结果
