Custom .ttf fonts to use in C# windows.Form

前端 未结 3 1521
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 08:20

How do I use a custom .tff font file I have with my current windows.forms application? I read some where that I use it as an embedded resource, but how do I set it the Syst

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 09:00

    Use the AddFontResourceEx API function through p/invoke, passing FR_PRIVATE to prevent installing a global font. Then you should be able to pass the font name to the Font constructor as usual.

    Edit: If you use the PrivateFontCollection and load the font from an external file, you don't even need this. If you load the font from an embedded resource, use Ash's solution.

提交回复
热议问题