问题
Lets say we store KeyCode value as a string. How do you convert it back to KeyCode?
For example, I've captured a key on keydown event:
string modifier = e.Modifiers.ToString(); // Control
string key_string = e.KeyCode.ToString(); // D1
How to do the following ?
Keys old_key_restored = (Keys)key_string;
Code above doesn't work.
EDIT: Daniel is a life savior ;)
Keys key_restored = (Keys) Enum.Parse(typeof(Keys), key_key);
回答1:
Its just an enum so you can use Enum.TryParse
来源:https://stackoverflow.com/questions/12060513/converting-a-string-to-keys-in-c-sharp