Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty key names in C# (Forms)

I have a combobox which is populated by the Keys 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.

like image 492
Tibi Avatar asked Apr 03 '12 18:04

Tibi


1 Answers

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();

    comboBox1.Items.Add(keyName);
}
like image 87
Dr. Wily's Apprentice Avatar answered Oct 05 '22 00:10

Dr. Wily's Apprentice