Tuesday, October 12, 2010

Getting System Font Name & Size

Simple code to get the Font Name, Font Size

protected void Page_Load(object sender, EventArgs e)
{
//Get font name list
foreach (FontFamily oneFontFamily in FontFamily.Families)
{
ListBox1.Items.Add(oneFontFamily.Name);
}

// Get FontSize list
Type typeFontSize = typeof(FontSize);
FieldInfo[] fieldsFontSize = typeFontSize.GetFields();
int countFontSize = fieldsFontSize.Length;
for (int i = 1; i < countFontSize; i++)
{
FieldInfo fieldFontSize = fieldsFontSize[i];
ListItem item = new ListItem(fieldFontSize.Name);
ListBox2.Items.Add(item);
}

//Get Color list
Type typeColor = typeof(System.Drawing.KnownColor);
FieldInfo[] fieldsColor = typeColor.GetFields();
int countColor = fieldsColor.Length;
for (int i = 1; i < countColor; i++)
{
FieldInfo fieldColor = fieldsColor[i];
ListItem item = new ListItem(fieldColor.Name);
ListBox3.Items.Add(item);
}

//Get BorderStyle list
Type typeBorderStyle = typeof(BorderStyle);
FieldInfo[] fieldsBorderStyle = typeBorderStyle.GetFields();
int countBorderStyle = fieldsBorderStyle.Length;
for (int i = 1; i < countBorderStyle; i++)
{
FieldInfo fieldBorderStyle = fieldsBorderStyle[i];
ListItem item = new ListItem(fieldBorderStyle.Name);
ListBox4.Items.Add(item);
}


}

No comments: