SharpAffair SharpAffair - 1 year ago 128
C# Question

.NET System.Drawing.Font - Get Available Sizes and Styles

I have one combo that allows user to select a font name.

The 2nd is supposed to show available sizes of the font. The 3rd has to show available styles.

Question: how can I retrieve the sizes and styles selected System.Drawing.Font supports?

Answer Source

You could use the InstalledFontCollection class to retrieve the available fonts and then enumerate them as shown in this MSDN article.

InstalledFontCollection installedFontCollection = new InstalledFontCollection();

// Get the array of FontFamily objects.
fontFamilies = installedFontCollection.Families;

// The loop below creates a large string that is a comma-separated
// list of all font family names.

int count = fontFamilies.Length;
for (int j = 0; j < count; ++j)
    familyName = fontFamilies[j].Name;
    familyList = familyList + familyName;
    familyList = familyList + ",  ";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download