从 C# 应用程序上的文件加载字体 [英] Load fonts from file on a C# application

查看:27
本文介绍了从 C# 应用程序上的文件加载字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

这是一种类似于this的问题,但不是来自动态链接库.我想从字体文件加载.

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

推荐答案

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

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

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

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.

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

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

这篇关于从 C# 应用程序上的文件加载字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆