【问题标题】:Installing and using a specific font in a winform在 winform 中安装和使用特定字体
【发布时间】:2013-01-09 08:32:35
【问题描述】:

我想在我的 winform 应用程序中使用特定字体。此字体将从我的应用程序资源自动安装在用户个人计算机中。

我该怎么做?

我使用了一些来自用户个人计算机的代码。如果我使用它,font 必须以前保留在用户个人计算机中,但我不希望这样。

         System.Drawing.Text.PrivateFontCollection fontCollection = new     System.Drawing.Text.PrivateFontCollection();
         fontCollection.AddFontFile(@"C:\Windows\Fonts\SUTOM__.TTF");
         FontFamily family = new FontFamily("SutonnyMJ", fontCollection);
         Font font3of9 = new Font(family, 15);
         label1.Font = font3of9;

【问题讨论】:

    标签: c# winforms fonts installation


    【解决方案1】:

    1.使用安装项目安装

    你可以从你的安装项目中安装字体来做到这一点,你必须这样做

    文件系统>在目标机器上的文件系统下右击>添加特殊文件夹字体文件夹

    然后选择字体文件夹和Add > File...

    2。以编程方式安装字体
    不幸的是,要实现这一点,您必须进行一些外部调用。

    [DllImport("gdi32.dll", EntryPoint="AddFontResourceW", SetLastError=true)]
    public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)]
                                             string lpFileName);
    

    然后从你想要的任何地方调用它

    AddFontResource(@"C:\FontLocation\MyFont.TTF");
    

    【讨论】:

    • +1 表示第一部分。关于第二部分,AddFontResource 只是临时添加字体,直到重新启动。 (见备注here)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 2017-06-09
    • 2021-10-13
    • 2012-11-14
    • 1970-01-01
    相关资源
    最近更新 更多