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.
Re: how to signal WinForm control input out of range?
jaeusm:
This sounds like the right approach, but when I created an event handler numEnter_LostFocus, it doesn't get invoked by entering out-of-range input into NumericUpDown control numEnter;
Re: how to signal WinForm control input out of range?
Only one item can have focus on the screen at any given time. The focused item can accept keyboard input, which is why only one item can have focus at a time. It doesn't make any sense for a control that accepts keyboard input to validate the value until the user is done entering it from the keyboard. The only way a control can know that the user is finished entering characters is when it loses focus. For a control to lose focus, some other item on the screen must 'get' focus.
Re: how to signal WinForm control input out of range?
jaeusm:
Suppose you want the NumericUpDown control to consider the number input by the user to be officially "entered" when the user presses the Enter key? The NumericUpDown control already behaves that way, and I don't want to change that. But in such a case, the focus is still on the NumericUpDown control.
Re: how to signal WinForm control input out of range?
As I mentioned before, you need to handle the appropriate event. Just look at the available events. In this case, use the ValueChanged event. You could also handle the KeyDown event and check to see if enter was pressed.