[Solved] WinForms Textbox only allow numbers between 1 and 6


Have you tried SupressKeyPress?

if (e.KeyCode < Keys.D1 || e.KeyCode > Keys.D6 || e.Shift || e.Alt)
        {
            e.SuppressKeyPress = true;
        }

        if (e.KeyCode == Keys.Back)
        {
            e.SuppressKeyPress = false;
        }

The 2nd If makes you able to press backspace if you want to change what you wrote.

solved WinForms Textbox only allow numbers between 1 and 6