Installed Font Name List Using VB Generator

Description: Generates a list of currently installed font name strings to be used for things like drop down combo boxes. This was created to show an example of generation using the Yield keyword.
Tested Platform: .NET 4.5, Visual Studio 2012, Windows 7
Language: VB.NET
' List installed font family names using generator 

Public Iterator Function listInstalledFontsYield() As IEnumerable(Of String)

    Dim InstalledFonts As New System.Drawing.Text.InstalledFontCollection()

    Dim families() As FontFamily = InstalledFonts.Families

    Dim fontNames(families.Length - 1) As String

    For i = 0 To families.Length - 1
        Yield families(i).Name
    Next
End Function

Submitted: April 25, 2013

Return to the snippets listing