Installing and using a specific font in a winform

前端 未结 1 551
挽巷
挽巷 2021-01-21 15:42

I want to use a specific font in my winform app. This font will be auto installed in user personal computer from my application resource.

How can I do that?

I us

相关标签:
1条回答
  • 2021-01-21 16:18

    1. Install Using Setup Project

    You can install font from your setup project to do this you have to

    File System > Right Click under the File System on Target Machine > Add Special Folder Fonts Folder

    Then Select Fonts Folder and Add > File... Add Font Folder SS

    2. Install Font Programmatically
    To achive this you have to do some external calls unfortunately.

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

    Then call it from anywhere you want

    AddFontResource(@"C:\FontLocation\MyFont.TTF");
    
    0 讨论(0)
提交回复
热议问题