I am using a NumericUpDown in WinForms and I'm wondering if it is possible to restrict the number of digits. So my max value is set to 9999.99 but you can enter values larger than this. you shouldn't be able to enter more than 4 digits to the left of the decimal and you shouldn't be able to enter more than 2 digits to the right of the decimal. There is another component called DoubleTextBox which uses the NumberFormatInfo.NumberDecimalDigits property to achieve this, but i was wondering if there is something similar for NumericUpDown. I've tried using the KeyDown event to stop the keyboard press but it doesn't work as perfectly. Any help would be great !
EditControl of your NumericUpDown and handle the input directly (you cannot test the Text property of the NUD, because it's updated after the Edit notifies the change: so, too late). You can then handleWM_KEYDOWNand accept the input only if it doesn't violate the rules you have set. - The debugger(s) guy(s) will hate you.