СообЧа > База Знаний > Программирование > Visual Basic

Вопрос

Как программно установить шрифт?

Ответ

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
Dim AppPath As String
Private Sub Form_Load()
     'The KPD-Team 2001
     'URL: http://www.allapi.net/
     'E-Mail: KPDTeam@Allapi.net
     AppPath = App.Path
If Right$(AppPath, 1) <> "\" Then AppPath = AppPath + "\"
     'Add the font to the Windows Font Table
     AddFontResource AppPath + "myfont.ttf"
     'Write something on the form
     Me.AutoRedraw = True
     Me.FontName = "myfont"
     Me.Print "This is a test!"
End Sub
Private Sub Form_Unload(Cancel As Integer)
     'Remove the font from the Windows Font Table
     RemoveFontResource AppPath + "myfont.ttf"
End Sub

Krueger



Copyright © 2000-2004 Сообщество Чайников
Контактная информация