zoukankan      html  css  js  c++  java
  • C#嵌入字体

    1:将字体文件(*.ttf)添加到资源文件里,注意资源的名称

    2:在Program.cs文件里声明 

    using System;
    using System.Collections.Generic;
    using System.Drawing.Text;
    using System.Windows.Forms;
    
    namespace SyncTime {
        static class Program {
            public static PrivateFontCollection privateFontCollection = new PrivateFontCollection();
    
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main() {
                byte[] fontData = Properties.Resources.DS_Digital;
                //打开"允许不安全代码编译"开关,此句才不报错 
                unsafe {
                    fixed (byte* pFontData = fontData) {
                        privateFontCollection.AddMemoryFont((System.IntPtr)pFontData, fontData.Length);
                    }
                }
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmMain());
            }
        }
    }

    3:使用

    Font fn = new Font(Program.privateFontCollection.Families[0], 16, FontStyle.Regular);
    this.Font = fn;
  • 相关阅读:
    阴影及定位
    选择器高级、样式及布局
    css的导入与基础选择器
    html知识
    ORM
    python实现进度条
    MySQL单表查询
    一、HTTP
    mysql4
    练习——MySQL
  • 原文地址:https://www.cnblogs.com/zh33gl/p/7530382.html
Copyright © 2011-2022 走看看