Font is installed? function

font-family, fonts, vb.net, visual-studio, visual-studio-2012

Solution

here IS

    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

Problem

I can improve my function to not search by each element? ``` #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 ``` UPDATE: Ok now I saw the ".tolist" function and now my code is like this: ``` 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 ``` I have the same question: Is best improved by the second way, or I can improve it better?

Original source