Bind fonts to a dropdownlist in C#

May 14, 2006

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:

<asp:DropDownList runat="Server" id="ddlFonts" />

Then call this method to do the actual databinding of the fonts:

private void BindFonts()
{
   System.Drawing.Text.InstalledFontCollection col = new System.Drawing.Text.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.

* $4.95/month BlogEngine.net Hosting – Click Here!
Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.