2013-04-08 65 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