Ele*_*ios 3 vb.net fonts visual-studio font-family visual-studio-2012
我可以改进我的功能而不是按每个元素搜索吗?
#Region " Font Is Installed? Function "
' [ Font Is Installed? Function ]
'
' Examples :
' MsgBox(Font_Is_Installed("Lucida Console"))
Private Function Font_Is_Installed(ByVal FontName As String) As Boolean
Dim AllFonts As New Drawing.Text.InstalledFontCollection
For Each Font As FontFamily In AllFonts.Families
If Font.Name.ToLower = FontName.ToLower Then Return True
Next
Return False
End Function
#End Region
Run Code Online (Sandbox Code Playgroud)
更新:
好吧,现在我看到了“.tolist”函数,现在我的代码是这样的:
Private Function Font_Is_Installed(ByVal FontName As String) As Boolean
Dim AllFonts As New Drawing.Text.InstalledFontCollection
Dim FontFamily As New FontFamily(FontName)
If AllFonts.Families.ToList().Contains(FontFamily) Then Return True Else Return False
End Function
Run Code Online (Sandbox Code Playgroud)
我也有同样的问题:是最好通过第二种方式改进,还是我可以改进得更好?
这是
Public Shared Function IsFontInstalled(ByVal FontName As String) As Boolean
Using TestFont As Font = New Font(FontName, 10)
Return CBool(String.Compare(FontName, TestFont.Name, StringComparison.InvariantCultureIgnoreCase) = 0)
End Using
End Function
Run Code Online (Sandbox Code Playgroud)