如何从VB和C#中的文件加载字体? [英] How to load a font from a file in VB and C#?

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

问题描述

我想从文件中加载VB Form程序中的字体。例如:我的字体在我的.exe程序的同一个文件夹中,我希望它保留一个外部资源(我们可以替换它,以便它改变整个程序的字体)。

解决方案

以下是您可以在C#中完成的示例:

  System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection(); 
privateFonts.AddFontFile(C:\\Documents and Settings\\somefont.ttf);
System.Drawing.Font font = new Font(privateFonts.Families [0],12);
label1.Font = font;

或者,在VB.NET中:

<$ ($ C $ \ Documents and Settings \somefont.ttf)
(code $) Dim font As New System.Drawing.Font(privateFonts.Families(0),12)
label1.Font = font

请参阅以了解更多详情。


I want to load a font in my VB Form program from a file.

e.g.: My font is in the same folder of my .exe program, and I want it to stay an external resource (that we can replace so that it change the entire program's font).

解决方案

Here's and example of how you can do it in C#:

System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();
privateFonts.AddFontFile("C:\\Documents and Settings\\somefont.ttf");
System.Drawing.Font font = new Font(privateFonts.Families[0], 12);
label1.Font = font;

Or, in VB.NET:

Dim privateFonts As New System.Drawing.Text.PrivateFontCollection()
privateFonts.AddFontFile("C:\Documents and Settings\somefont.ttf")
Dim font As New System.Drawing.Font(privateFonts.Families(0), 12)
label1.Font = font

Look THIS for more details.

这篇关于如何从VB和C#中的文件加载字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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