vb.net 在我的 winform 标签中使用自定义字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13573916/
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-09-17 11:19:04  来源:igfitidea点击:

Using custom fonts in my winform labels

vb.netvisual-studio-2010

提问by Scott

I wonder if its possible to use a custom font for my form labels without installing it on the users machine? I would like to display a text using a font I have rights to, but its not installed on the potencial user machine.

我想知道是否可以为我的表单标签使用自定义字体而不在用户机器上安装它?我想使用我有权使用的字体显示文本,但它没有安装在潜在的用户机器上。

Are there any solutions for this?

有什么解决办法吗?

回答by Neolisk

Here is the extract (using PrivateFontCollection):

这是摘录(使用PrivateFontCollection):

Dim pfc As New PrivateFontCollection()
pfc.AddFontFile("C:\Path To\PALETX3.ttf")
label1.Font = New Font(pfc.Families(0), 16, FontStyle.Regular)

Converted from here: Load And Use Custom Font Without Installing It.

从这里转换:加载和使用自定义字体而不安装它

Also check this: Embedding/deploying custom font in .NET app

另请检查:在 .NET 应用程序中嵌入/部署自定义字体

回答by gfxdevelopers

Add this code in Top of your Code

将此代码添加到您的代码顶部

Imports System.Drawing.Text

Add this code on Form1_Load() to change the Lablel1.Font

在 Form1_Load() 上添加此代码以更改 Labell1.Font

Dim customfont As PrivateFontCollection = New PrivateFontCollection
customfont.AddFontFile("C:\maven.ttf")
Label1.Font = New Font(customfont.Families(0), 10)

Tested on Visual Basic 2010 Enterprises Edition

在 Visual Basic 2010 企业版上测试