It will not show any message but it will prevent you from wrong input. @HamishGrubijan, IsControl has nothing to do with the Control key; it returns whether or not a char is a control char. (event.keyCode>=65 && event.keyCode<=90 ) && event.keyCode!=32);">, . NumericUpDown is actually a collection of controls containing a text box and a "spin box" (up down buttons) and some code handling input validation. Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand ; Advertising Reach developers & technologists worldwide Reach developers & technologists worldwide We are sorry that this post was not useful for you! evt.which : event .keyCode if (charCode > 31 && (charCode < 48 || charCode > 57 )) return false ; return true ; } Here we have used the KeyPress event to limit our textbox to numeric values only. In the above code, we create a text box that only accepts numeric values from the user with the NumberUpDown view in C#. It handles floating point numbers, but can easily be modified for integers. Why did OpenSSH create its own key format, and not use PKCS#8? Allow pressing of the Delete, Backspace, and Tab keys. I have asked the same question before, the thread becomes messy somewhat. source http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=VS.90).aspx, 3) using the MaskedTextBox: http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx. create a class into your project, like this. msdn.microsoft.com/en-us/library/sdx2bds0(v=vs.110).aspx, http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx, http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=VS.90).aspx, http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx, Microsoft Azure joins Collectives on Stack Overflow. Did Richard Feynman say that anyone who claims to understand quantum physics is lying or crazy? By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. You would hope that the form validation would catch that though, since at some point you're gonna want to do an Int32.TryParse or something. It supports copy/paste operations and negative numbers: Update 2017: My first answer has some issues: So I came up with another version that's more generic, that still supports copy/paste, + and - sign, etc. In the numericUpDown1_KeyPress() function, we have added a check for . Performance Regression Testing / Load Testing on SQL Server, Using a Counter to Select Range, Delete, and Shift Row Up.