2013-04-08 66 views
0

我想中检索安装的字体的信息获取信息,我已经通过这种方式试图有关安装的字体

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... 

回答

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 
+0

不要设置变量一样,在净没什么。它在vb6时代曾经是必需的,但对于.Net的垃圾收集器来说,它对存储器收集没有任何影响或负面影响。 – 2013-04-08 14:31:22

+0

注意到并注释掉。 Thx – APrough 2013-04-08 14:57:14

+0

谢谢你的答案! – ElektroStudios 2013-04-09 08:37:57

1
Private Function Get_Installed_Fonts() As FontFamily() 
    Using AllFonts As New Drawing.Text.InstalledFontCollection 
     Return AllFonts.Families 
    End Using 
End Function 
+0

糟糕:我首先误解了这个问题。我想删除我的答案,但我想我会留下代码,因为它现在对你正在做的事情还有一些改进。 – 2013-04-08 13:43:28

+0

谢谢你的修改功能 – ElektroStudios 2013-04-09 08:37:26