Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet the pitch (fixed or variable) of each font available on the system
Keywordsfont, font pitch, fixed width, variable width
CategoriesGraphics
 
Enumerate the fonts in the Screen.Fonts collection. Use GetTextMetrics to see which are fixed and which are variable pitch.
 
Private Sub Form_Load()
Dim i As Long
Dim font_name As String
Dim tm As TEXTMETRIC

    flxFonts.AllowUserResizing = flexResizeColumns
    flxFonts.Rows = Screen.FontCount + 1
    flxFonts.FixedRows = 1
    flxFonts.Cols = 2
    flxFonts.TextMatrix(0, 0) = "Font Name"
    flxFonts.TextMatrix(0, 1) = "Pitch"

    For i = 0 To Screen.FontCount - 1
        ' Select the font.
        font_name = Screen.Fonts(i)
        Font.Name = font_name
        flxFonts.TextMatrix(i + 1, 0) = font_name

        ' Get the font's metrics.
        GetTextMetrics hdc, tm

        ' See if it is fixed width.
        If (tm.tmPitchAndFamily And FIXED_PITCH) = 0 Then
            flxFonts.TextMatrix(i + 1, 1) = "Fixed"
        Else
            flxFonts.TextMatrix(i + 1, 1) = "Variable"
        End If
    Next i

    SizeColumns flxFonts
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated