从 C# 应用程序上的文件加载字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/544972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 07:36:32  来源:igfitidea点击:

Load fonts from file on a C# application

c#.netwinformsfonts

提问by FerranB

I wish to load and use a font to a desktop application in C#. It's that possible without installing the font on the system?

我希望在 C# 中为桌面应用程序加载和使用字体。在系统上不安装字体可以吗?

It's a kind of question like thisbut not from a DLL. I want to load from font file.

这是一种类似问题的这个而不是从一个DLL。我想从字体文件加载。

采纳答案by John Leidegren

There's a class System.Drawing.Text.PrivateFontCollection in System.Drawing.dll which can manage fonts on a per application basis.

System.Drawing.dll 中有一个 System.Drawing.Text.PrivateFontCollection 类,它可以在每个应用程序的基础上管理字体。

All you do is that you maintain this collection within your app and you add fonts through AddFontFile or AddMemoryFont and you'll then be able to use that font as if it was installed on your system.

您所做的就是在您的应用程序中维护此集合,并通过 AddFontFile 或 AddMemoryFont 添加字体,然后您就可以使用该字体,就像它已安装在您的系统上一样。

It's like installing the font for the application only. The font will be uninstalled once the process terminates.

这就像仅为应用程序安装字体。一旦进程终止,字体将被卸载。

回答by Adrian Hum

Load a font from disk, stream or byte array

从磁盘、流或字节数组加载字体

Try this...

尝试这个...

The blog describes how to use the FontCollection classes.

该博客描述了如何使用 FontCollection 类。