how do you make sure a font gets installed with your vb.net application

Dov_B
Dov_B used Ask the Experts™
on
I have a vb.net 2008 express application that needs a particular font installed on the users machine how do do that
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jorge PaulinoIT Pro/Developer
Top Expert 2008
Commented:
You can check in the windows\font\ if the font was already installed.
Something like:

        If IO.File.Exists("C:\WINDOWS\Fonts\FontName.ttf") Then
            ' font installed
        End If

Open in new window

Author

Commented:
I did not know that Thank you
but what I meant to ask is how do I tell vb.net to install the font
IT Pro/Developer
Top Expert 2008
Commented:
Check this example:
Public Class Form1
 
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       IO.File.Copy("c:\Ayuma2yk.ttf", "c:\windows\fonts\Ayuma2yk.ttf", True)
       FontUtil.InstallFont("Ayuma2yk.ttf")
   End Sub
 
End Class
 
 
Public Class FontUtil
 
   Private Declare Function AddFontResource Lib "gdi32" Alias "AddFontResourceA" (ByVal lpFileName As String) As Long
   Private Declare Function RemoveFontResource Lib "gdi32" Alias "RemoveFontResourceA" (ByVal lpFileName As String) As Long
 
   ''' <summary>
   ''' Installs the font
   ''' </summary>
   ''' <param name="FileName">Name of the File </param>
   Public Shared Function InstallFont(ByVal FileName As String) As Boolean
       InstallFont = AddFontResource(FileName) <> 0
   End Function
 
   ''' <summary>
   ''' Uninstalls the font
   ''' </summary>
   ''' <param name="FileName"> Name of the File </param>
   Public Shared Function UninstallFont(ByVal FileName As String) As Boolean
       UninstallFont = RemoveFontResource(FileName) <> 0
   End Function
 
End Class

Open in new window

Éric MoreauSenior .Net Consultant
Top Expert 2016
Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial