Tibi Tibi - 1 year ago 113
C# Question

Pretty key names in C# (Forms)

I have a combobox which is populated by the

enumeration (winforms).

The problem is that the key names are not very clear for inexperienced users. For example, the average user may not know what 'OemPipe', or 'HanjaMode' means. So, how can I solve this issue, and have some better key names?

I'm thinking of making a dictionary with the keys and their names, but populating the dictionary myself is very time consuming.

Answer Source

Make a resource file that maps key names to a user-understandable string. If the resource file does not have a value for a particular key, then just go with the Key name (as you are doing now), so that way you only have to define the ones that are difficult to understand, and you don't have to do them all up front.

This also allows you to localize to different languages, if you like.

EDIT: Added code example. Assumption is that you have a resource file named "KeyNames.resx"

foreach (var key in Enum.GetValues(typeof(Keys)))
    var keyName = KeyNames.ResourceManager.GetString(key.ToString());
    if (keyName == null)
        keyName = key.ToString();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download