Library code snippets

List Installed Fonts

Nearly every text editor needs a combo box listing all the fonts installed on the PC, so the user can choose what font some text appears in. Fortunately, this is very simple in VB, using the Screen.Fonts() array. You could also use the Printer.Fonts() array to list the available printer fonts.

Private Sub Form_Load()
    Dim I As Integer ' Declare variable. 
    For I = 0 To Screen.FontCount -1 ' Determine number of fonts. 
        List1.AddItem Screen.Fonts (I) ' Put each font into list box. 
    Next I
End Sub

Comments

  1. 21 Oct 2006 at 05:12

    i am getting error.... it says fontcount and font is not a member of screen.... wht to do....????help Plz........

  2. 09 Jul 2003 at 01:09

    If you wanted to Show the style of the FONT in real-time, just do the following:


    add list1 (listbox), label1 (label) to your form


    then in code:

    Code:

    Private Sub Form_Load()
    dim i as integer
       For i = 0 To Screen.FontCount - 1
           List1.AddItem Screen.Fonts(i)
       Next i
    End Sub


    Private Sub List1_Click()
    Label1.Font = List1.List(List1.ListIndex)
    End Sub


  3. 29 Oct 2002 at 14:07

    Yes, I'd like to know how to show a sample of the font.

  4. 27 Mar 2002 at 18:44

    this was great information, now being able to see an example of what each font looks like when a person clicks on it would be better

  5. 01 Jan 1999 at 00:00

    This thread is for discussions of List Installed Fonts.

Leave a comment

Sign in or Join us (it's free).