Results 1 to 6 of 6

Thread: Fonts --> Combobox ?

  1. #1
    Guest
    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.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    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%
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3
    Guest
    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

  4. #4
    Guest
    That will only work for ScreenFonts. To add Printer fonts, replace Screen with Printer.

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    ' Use the common dialog control to display all system fonts
    '
    'set the flag to fonts
    	CommonDialog1.Flags = cdlCFScreenFonts
    'show the fonts 
    	CommonDialog1.ShowFont
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    Guest
    Or use cdlCFBoth for both Printer and Screen fonts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width