-
What method do you use to fill a combobox with the names of available fonts?
I really don't want to delve into the fonts directory to do something this simple, is there an API for this?
I'm making a word processor 'cos i'm bored, you can have a copy when its finished if you like.
-
Code:
Private Sub Form_Load()
Dim intBuffer As Integer, strFont As String
'load printer fonts to combobox
If Dir$(App.Path & "\fonts.dat") = "" Then
'font file doesnt exist. Create it.
Open App.Path & "\fonts.dat" For Output As #1
For intBuffer% = 0 To Printer.FontCount - 1
Call cmbFonts.AddItem(Printer.Fonts(intBuffer%))
Print #1, Printer.Fonts(intBuffer%)
Next intBuffer%
Close #1
Else
'load fonts from file
Open App.Path & "\fonts.dat" For Input As #1
While Not EOF(1)
Input #1, strFont$
Call cmbFonts.AddItem(strFont$)
Wend
Close #1
End If
cmbFonts.ListIndex = 0
''cmbFonts.Sorted = True 'Alphabetize list
'set combobox to "Arial"
For intBuffer% = 0 To cmbFonts.ListCount - 1
If cmbFonts.List(intBuffer%) = "Arial" Then cmbFonts.ListIndex = intBuffer%: Exit For
Next intBuffer%
-
Try this:
Code:
Private Sub Form_Load()
For i = 0 To Screen.FontCount - 1
Combo1.AddItem (Screen.Fonts(i))
Next i
End Sub
Private Sub Combo1_Change()
text1.FontName = Combo1.Text
End Sub
Private Sub Combo1_Click()
text1.FontName = Combo1.Text
End Sub
-
That will only work for ScreenFonts. To add Printer fonts, replace Screen with Printer.
-
<?>
Code:
' Use the common dialog control to display all system fonts
'
'set the flag to fonts
CommonDialog1.Flags = cdlCFScreenFonts
'show the fonts
CommonDialog1.ShowFont
-
Or use cdlCFBoth for both Printer and Screen fonts.