In a KeyDown event, I have the KeyEventArgs to work with. It has (among other things) these three properties:
e.KeyCodee.KeyDatae.KeyValue
Which one should I use for what?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit: Somehow I misread your question to include checking a valid character. Did you modify it? I’ve added a description of each.
If you just need the character, I’d probably recommend using the KeyPress event and using the KeyPressEventArgs.KeyChar property. You can then use Char.IsLetterOrDigit() to find out if it’s a valid character.
Alternatively, you might be able to cast KeyEventArgs.KeyCode to a char and then use Char.IsLetterOrDigit on that.