How to make a textbox that only accepts numbers in C#?There are many ways to make a textbox to only accepts numbers in C#.
1) Use a
NumericUpDowninstead. NumericUpDown does the filtering for you, which is nice. Of course it also gives your users the ability to hit the up and down arrows on the keyboard to increment and decrement the current value.
2) Handle the appropriate keyboard events to prevent anything but numeric input. I've had success with this two event handlers on a standard TextBox: