Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » how to signal WinForm control input out of range?
Closed Thread
Old 03-05-2009, 03:08 PM   #1 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default how to signal WinForm control input out of range?

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 is offline  
Old 03-05-2009, 03:49 PM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: how to signal WinForm control input out of range?

You just need to handle the appropriate event (probably the LostFocus event) and display a message box in that method.
jaeusm is offline  
Old 03-05-2009, 05:31 PM   #3 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default 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;
BobLewiston is offline  
Old 03-06-2009, 10:21 AM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default Re: how to signal WinForm control input out of range?

Quote:
it doesn't get invoked by entering out-of-range input into NumericUpDown control numEnter
Correct. As the name of the event implies, it gets invoked when the control loses focus, which is when the value would be set anyway.
jaeusm is offline  
Old 03-06-2009, 11:03 AM   #5 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default Re: how to signal WinForm control input out of range?

Quote:
Originally Posted by jaeusm View Post
Correct. As the name of the event implies, it gets invoked when the control loses focus, which is when the value would be set anyway.
I guess I don't understand what it means to "lose focus". Does that mean when the flow of control passes from the WinForm control?
BobLewiston is offline  
Old 03-06-2009, 01:07 PM   #6 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default 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.
jaeusm is offline  
Old 03-06-2009, 05:11 PM   #7 (permalink)
 
Junior Techie

Join Date: Nov 2008

Posts: 79

BobLewiston is on a distinguished road

Default 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.
BobLewiston is offline  
Old 03-06-2009, 05:39 PM   #8 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default 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.

Last edited by jaeusm; 03-06-2009 at 05:46 PM.
jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Black Viper's Top tweaks for a faster PC xXxexpertxXx Overclocking, Case Mod, Tweaking PC Performance 0 02-21-2008 10:04 PM
Sound Card Tips EricB Computer Audio & Multimedia 2 02-18-2008 01:37 AM
No Signal Input dhgunit Hardware Troubleshooting 2 11-13-2007 12:23 AM
Signal Over Range? Very Weird Trick Hardware Troubleshooting 1 03-31-2007 01:32 PM