I want to restrict what numbers and letters can be entered into a textbox. Let\'s say I only want to allow numbers 0-5 and letters a-d (both lower and uppercase). I already tri
Override the PreviewKeyDownEvent like this:
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.A || e.KeyCode == Keys.B || ...)
e.IsInputKey = true;
else
e.IsInputKey = false;
}
This will tell the textBox which keys it will consider as a user input or not.