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

[ad_1]

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.

[ad_2]

solved WinForms Textbox only allow numbers between 1 and 6