by
Neon Quach
18. November 2009 04:20
In this blog I will give you snippet code which fetches installed font in dropdownlist in .NET using both C# and VB.NET.
Start with creating a new website using asp.net C# and VB.NET.
Drag a dropdownlist from toolbox into web page.
Here is markup:
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true">
<asp:ListItem>--- Please select font ---</asp:ListItem>
</asp:DropDownList>
Paste code bellow and put on your page load event.
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InstalledFontCollection instedFontColl = new InstalledFontCollection();
DropDownList1.DataSource = from font in instedFontColl.Families
select font.Name;
DropDownList1.DataBind();
}
}
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim fonts As New InstalledFontCollection()
DropDownList1.DataSource = From font In fonts.Families _
Select font.Name
DropDownList1.DataBind()
End If
End Sub
Press F5 or Ctrl + F5 you will see the result like screenshot bellow.

Happy programming
Binding-Installed-fonts-in-dropdownlist-using-LINQ.rar (8.77 kb)