1 Previous Next 

How to get all installed font types


TommyTwoTrain made again a nice sample in the Microsoft forums. He writes always it is easy. But that is of course only if you know how to do it. The example only does 3 styles reg, bold, italic. One can add others like underline etc as desired.

Imports
System.Drawing.Text
Public Class Form1
    Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim f As Font
        Dim FontList As New List(Of Font)
        Dim installed_fonts As New InstalledFontCollection
        Dim font_families() As FontFamily = installed_fonts.Families()
        For Each font_family As FontFamily In font_families
            If font_family.IsStyleAvailable(FontStyle.Regular) Then
                f = New Font(font_family, 14, FontStyle.Regular)
                FontList.Add(f)
            End If
            If font_family.IsStyleAvailable(FontStyle.Bold) Then
                f = New Font(font_family, 14, FontStyle.Bold)
                FontList.Add(f)
            End If
            If font_family.IsStyleAvailable(FontStyle.Italic) Then
                f = New Font(font_family, 14, FontStyle.Italic)
                FontList.Add(f)
            End If
        Next font_family
        For Each f In FontList
            RichTextBox1.SelectionFont = New Font(f.FontFamily, 12, f.Style)
            RichTextBox1.AppendText(f.FontFamily.Name & "   " & f.Style.ToString & vbLf)
        Next
    End Sub
End Class

 

 




1 Previous Next