Why the FontFamily param of the Font object is a string and not an enum?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
FontFamily refers to the name of the Font. While you could use ‘monospace’ or ‘serif’ I wouldn’t think it would be supported by .Net.
Remember, using a enum would be impossible. A enum is a static compile-time feature, which means that it can’t ‘generate’ a enum dynamically from fonts on your system. Indeed, including anything this specific in a language would probably be a poor idea. Even if this was supported, the user’s machine wouldn’t have the same fonts as yours – some fonts would be incorrectly included in the list and some excluded (because once compiled an enum becomes ‘final’).
Enums are a convenient store of integral constants and NOTHING else. Each item in a enum has a convenient name and a value, even if you don’t specify it. The following two enums are the same.
And there are two other problems, enum names can not contain spaces, where font names can. Getting the fields from an enum is not a trivial task (it requires a lot of reflection code).
The following code will get you a list of fonts (you will need to add System.Drawing as a reference):