Bind Fonts to a dropdownlist in c#

I recently had to make a dropdownlist populated with fonts. Luckily, .NET allows you to use the installed fonts very easy. First, add a drowdownlist to your ASP.NET page like this: Then call this method to do the actual databinding of the fonts: //using System.Drawing.Text;

private void BindFontsToDropdownlist()
    {
        InstalledFontCollection col = new InstalledFontCollection();

        foreach (System.Drawing.FontFamily family in col.Families)
        {

            ddlFonts.Items.Add(family.Name);
        }

    }
That's all there is to it. Be aware that the fonts are the ones installed on the server hosting your web page.

No comments:

Post a Comment