Installed Font Name List Using 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.8, Visual Studio 2022, Windows 10
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

Posted: March 20, 2023

Return to the snippets listing