0

我想检索已安装字体的信息,我尝试过这种方式:

Private Function Get_Installed_Fonts() As Array
    Dim AllFonts As New Drawing.Text.InstalledFontCollection ' Get the installed fonts collection.
    Dim FontFamilies() As FontFamily = AllFonts.Families()   ' Get an array of the system's font familiies.
    Return FontFamilies ' Return the array
End Function

然后我可以做...:

   For Each Font As FontFamily In Get_Installed_Fonts()
       MsgBox(Font.Name)
   Next

但我找不到这样做的方法:

    For Each Font As FontFamily In Get_Installed_Fonts()
        MsgBox(Font.IsSystemFont)
        MsgBox(Font.OriginalFontName)
        MsgBox(Font.SizeInPoints)
    Next

我在那里缺少什么?

这就是我将获得的东西,我还需要一种方法来搜索是否安装了字体,例如:

If FontsArray.contains("FontName") Then...
4

2 回答 2

1

问题是 .IsSystemFont、.OriginalFontName 和 .SizeInPoints 属性是 Font 类的成员,而不是 FontFamily。FontFamily 用于创建 Font,此时您可以使用上述语言获取信息。

所以,你可以做...

For Each FontFam As FontFamily In Get_Installed_Fonts()
    Dim tFont as new Font(FontFam.Name, 8)
    MsgBox(tFont.IsSystemFont)
    MsgBox(tFont.OriginalFontName)
    MsgBox(tFont.SizeInPoints)
    'tFont = nothing
Next
于 2013-04-08T13:39:10.473 回答
1
Private Function Get_Installed_Fonts() As FontFamily()
    Using AllFonts As New Drawing.Text.InstalledFontCollection 
        Return AllFonts.Families
    End Using
End Function
于 2013-04-08T13:40:47.847 回答