I set a minimum value of 1 and maximum of 10 for my "numericUpDown1". (C# Windows Form)
When I enter the value 0 manually from the keyboard, "numericUpDown1" automatically increases to 1, and when I enter a value greater than 10 manually from the keyboard, "numericUpDown1" automatically decreases to 10.
Is it possible for me to change these automatic returns? Ex: If I type 25, it will return 3 instead of 10.
Is there any option/property to change this?
I tried some options like "Validated", "Validating", "Leave" and "ValueChanged". But that didn't work.
When it is <=0 or >10, I wanted to return an error (messagebox) and automatically return the value of "numericUpDown1" to 1.
One way to do this is to handle the
KeyDownevent. The approach I would personally use is to inheritNumericUpDownand replace instances of it in the MainForm.Designer.cs file with my custom class. Now, if you set the value ofMaximumto 10 in the designer it will behave the way you describe.You'll also want to do the same kind of action when the control loses focus.