Converting enum Keys value to string

  • Thread starter Thread starter Ahmed
  • Start date Start date
A

Ahmed

I am saving the enum value of specific keys to an xml file which i then
need to get the string representation. I believe KeysConverter is there
for that but i have trouble using it for my purpose.
i want to give it a value and have it spit out its Keys equivilancy for
example.

121 -> Keys.F10

I am not sure if i am playing with the right function or not but any
advise or suggestions would be appreciated :)
 
For enum to int conversion use a cast:

int i = (int)Keys.F10;
Keys k = (Keys)i;

For enum to string conversion:

string s = Keys.F10.ToString();
Keys k = (Keys)Enum.Parse(typeof(Keys), s);


Rob.
 
Back
Top