Is there a way (perhaps via EventArgs) to signal the app when a user tries to enter out-of-range input into a WinForm control? (Specifically, a number in a NumericUpDown control numericUpDown1 that is larger than numericUpDown1.Maximum?) Yes, I know the control won't allow the input, but I want to display an error message if this happens.
BobLewiston
0
Junior Poster
Recommended Answers
Jump to PostI would suggest something like that you would want to be an exception rather than event
Create an exception class and do a check before passing the value to the numeric control and throw an exception if out of bounds
Jump to PostOh i thought you were making your own control
You should be able to catch the validating event and get the value before it has changed back to maximum
Jump to PostIn the designer click on the events for the numeric control you are trying to catch the events for and double click on validating
Or on the codeside
numericcontrol.Validating += eventnamehere
Jump to PostYeh that didn't quite work as i thought it would have
What you can do instead is capture previewkeydown
add this to the existing field"12" + "4"
124
then check 124 to be greater than the max
All 13 Replies
dickersonka
104
Veteran Poster
BobLewiston
0
Junior Poster
dickersonka
104
Veteran Poster
BobLewiston
0
Junior Poster
dickersonka
104
Veteran Poster
BobLewiston
0
Junior Poster
dickersonka
104
Veteran Poster
BobLewiston
0
Junior Poster
dickersonka
104
Veteran Poster
BobLewiston
0
Junior Poster
dickersonka
104
Veteran Poster
BobLewiston
0
Junior Poster
dickersonka
104
Veteran Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.