Need help Converting Keys.Right

  • Thread starter Thread starter rayfusion
  • Start date Start date
R

rayfusion

I am storing Keys.Right in a string and I need to convert it to back to the
Keys Enumeration so I can handle it correctly. How do I do this?
 
I am currently using the following code: if (e.KeyCode == Keys.Right)

Users will have the options to change the key mappings so I decided to save
the changes to the App.config file. I am pulling the value from the
App.config file into a string called totalKey. So in the totalKey field, I
have the value of Keys.Right or (char)13. The code will now look like this
"if (e.KeyCode == totalKey)". I want to be able to convert totalKey into the
Key enum so e.KeyCode will respond to totalKey correctly.
 
I used the Enum.Parse and it worked like a charm.

Keys totalKey =
(Keys)Enum.Parse(typeof(Keys),ConfigurationManager.AppSettings["totalKey"]);

Thanks everyone!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top