简体   繁体   English

在C#应用程序中使用特定字体

[英]Using specific fonts in c# application

Basically, I am using a custom font in my project, which is installed in my OS. 基本上,我在项目中使用了自定义字体,该字体已安装在操作系统中。 The problem is that on client's PC this font is not installed, so application is using default font. 问题是在客户端的PC上未安装此字体,因此应用程序使用的是默认字体。

Is there any way to use that font inside application without every form/control code change? 有什么方法可以在应用程序内部使用该字体而无需更改每个表单/控制代码? The best solution would be to use font without installing it in system and changing every form/control code. 最好的解决方案是使用字体而不将其安装在系统中并更改每个表单/控制代码。

There's no global setting to do that. 没有全局设置可以做到这一点。

You will need to loops through all the controls in the form recursively, and change the font. 您将需要递归遍历表单中的所有控件,并更改字体。 Make a Base Form that inherits from Form. 制作一个从Form继承的基本Form。 Do the recursion. 进行递归。

Then make all your forms inherit from that base form. 然后,使所有表单都从该基本表单继承。 Use PrivateFontCollection to import the font and change the conrtol font. 使用PrivateFontCollection导入字体并更改conrtol字体。

var pfc = new PrivateFontCollection();
pfc.AddFontFile(@"C:\MyFont.ttf");
myControl.Font = new Font(pfc.Families[0], 14, FontStyle.Regular);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM