I want a TextBox to only accept some specific characters by using the KeyDown event. I've already got it working, except for one character, the single quote. To get the character that will be written I use (char)e.KeyValue
which works for all the characters except the quote (it gives Û). I know I could just use e.KeyCode
but it's value is Keys.Oem4
, which AFAIK might be different across systems.
Is there any way of consistently detecting a single quote key press?
Code snippet:
char c = (char)e.KeyValue;
char[] moves = { 'r', 'u', ..., '\'' };
if (!(moves.Contains(c) || e.KeyCode == Keys.Back || e.KeyCode == Keys.Space))
{
e.SuppressKeyPress = true;
}