You have several options.
Firstly you can enumerate all of the fonts installed on your system - see
How to: Enumerate Installed Fonts[
^]
If you want to build your own enum, you can have descriptions with spaces like this (ref:
c# - Can my enums have friendly names?[
^])
public enum FontFamilies
{
[Description("Ariel")]
Ariel,
[Description("Arial Narrow")]
ArialNarrow,
[Description("Times New Roman")]
TimesNewRoman
};
To get these descriptions you can do this (same ref as above):
public static string GetDescription(Enum value)
{
Type type = value.GetType();
string name = Enum.GetName(type, value);
if (name != null)
{
FieldInfo field = type.GetField(name);
if (field != null)
{
DescriptionAttribute attr =
Attribute.GetCustomAttribute(field,
typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attr != null)
{
return attr.Description;
}
}
}
return null;
}
An alternative method is to extend
enum
see -
c# - Can my enums have friendly names? - Stack Overflow[
^]
public enum FontFamilies2
{
Ariel,
ArialNarrow,
TimesNewRoman
};
public static class ExtensionMethods
{
public static string EnumValue(this FontFamilies2 e)
{
switch (e)
{
case FontFamilies2.Ariel:
return "Ariel";
case FontFamilies2.ArialNarrow:
return "Ariel Narrow";
case FontFamilies2.TimesNewRoman:
return "Times New Roman";
}
return "Where did you find that value";
}
}
And this is how you would access those descriptions respectively:
System.Diagnostics.Debug.Print(GetDescription(FontFamilies.TimesNewRoman));
System.Diagnostics.Debug.Print(FontFamilies2.TimesNewRoman.EnumValue());
[EDIT OP now states they want this description as a list]
Assuming you have gone for the
[Description...]
attribute then you can do this:
var fonts = new List<string>();
foreach (var x in Enum.GetValues(enumType: typeof (FontFamilies)))
fonts.Add(GetDescription(x as Enum));
or the Linq version
var fonts = (from object x in Enum.GetValues(enumType: typeof (FontFamilies)) select GetDescription(x as Enum)).ToList();