4

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?

Scott
  • 5,991
  • 15
  • 35
  • 42

2 Answers2

8

Here is the extract (using 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

Community
  • 1
  • 1
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
  • A potencial user wont have this font downloaded so I could use a path to load it I think. Is there a posibility to load a font using the resources? – Scott Nov 26 '12 at 22:22
  • @Scott: Yes, it is possible, see this link: [Use resource font directly in VB.net/C#](http://stackoverflow.com/questions/2928383/use-resource-font-directly-in-vb-net-c). – Victor Zakharov Nov 26 '12 at 23:35
1

Add this code in Top of your Code

Imports System.Drawing.Text

Add this code on Form1_Load() to change the Lablel1.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

LarsTech
  • 80,625
  • 14
  • 153
  • 225