Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
-->
TitleInstall a temporary font
Description
Keywordsfonts, install font, create font, remove font, uninstall font, temporary font
CategoriesUtilities, Windows, Graphics
 
By Andy Fielding.

Create a BAS (or CLS) module and add the following code to it:

 
' These subs temporarily install and uninstall a font
' for use while your program is running. You MUST
' call this code to install the font before loading
' any form that uses it, or you'll generate an error.
'
' For the sFontFile argument you pass to the subs, be sure
' to use the font's actual filename (e.g. "GOUDOS.TTF"), not
' its font name (e.g. "Goudy Old Style").

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

' To add the font
Public Sub AddFont(ByVal sFontFile As String)
Dim lResult As Long

    ' e.g.: lResult = AddFontResource("c:\myApp\myFont.ttf")
    lResult = AddFontResource(sFontFile)
End Sub

' To remove the font
Public Sub RemoveFont(ByVal sFontFile As String)
Dim lResult As Long

    ' e.g.: lResult =
    ' RemoveFontResource("c:\myApp\myFont.ttf")
    lResult = RemoveFontResource(sFontFile)
End Sub
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated