-
February 8th, 2006, 06:46 AM
#1
How to check if Up/Down Button is pressed on NumericUpDown Control...
Hi Friends,
I would like to know that how to check whether up/down button was clicked on the NumericUpDown Control in .NET 2005.
Any help would be greatly appreciated.
With warm regards,
KEDAR
-
February 8th, 2006, 07:20 AM
#2
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
check this event NumericUpDown1_ValueChanged
-
February 8th, 2006, 07:44 AM
#3
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
Thank you for your interest Mr. Anis Khan...
But the ValueChanged event occurs irrespective of whether you click up button or down button.
What i wanted to know is that if there is any way to determine specifically which button has been clicked.
Actually i was expecting that there should have been some value in Event Arguments of the event ValueChanged indicating up/down button pressed.
With warm regards,
KEDAR
-
February 8th, 2006, 10:08 AM
#4
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
In my opinion, the ValueChanged is the only event you could use for this!
There are methods
NumericUpDown.UpButton
NumericUpDown.DownButton
but they cannot be used to determine which was clicked, only to "click" them through code - understand¿
What you could perhaps do, is to have a variable indicating if the value of the numericupdown increases or decreases, because if the value increas, then automatically the up button was pressed, same with decrease.
Based on that, you can do what you want to when someone clicks up or down
I Hope I have been helpful.
-
February 8th, 2006, 09:21 PM
#5
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
You cannot determine that because you shouldn't really care. What matters in a NUD is the Value, so you should only care when that changes. If you want to know whether the Value has increased or decreased then store the old value in a variable and compare the two in the event handler. Note that the ValueChanged event is raised when the user manually types a value into the control and then moves focus, so it isn't just linked to the buttons.
-
February 9th, 2006, 12:17 AM
#6
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
Hi Friends,
I should thank you for all those valueable inputs.
The reason i want to know which button is clicked is that i need to change the value of the interval in the pre-determined ranges like:-
Value will increase by 1 in 1-20 and by 2 in 20-40 upto 60 and again when one clicks down button value should decrease by the same interval by which it has been increased in that range.
I am thinking of using a variable to keep track of the previous value or simply abandon the idea of using the numeric control and use simple textbox and 2 buttons.
With warm regards,
KEDAR
-
February 9th, 2006, 12:34 AM
#7
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
Are you doing this so that the user cannot enter values like 21, 23, etc. or are you just trying to make the NUD increment faster at higher values? If it's the former then you're out of luck as the user can type any number they want directly into the NUD anyway. If you absolutely want to restrict the value then you'd need to use a DomainUpDown instead and use a loop to populate it in the first place. If it's the latter you can manipulate the Increment property so that pressing a button changes the value by whatever amount you want. You could set the Increment to 1 below 20, change it to 2 above 20 and then to 3 above 60 or whatever. The problem comes at the boundaries. When the Value is 20 do you make the Increment 1 or 2, because you don't whether the next change will be up or down? It probably doesn't matter because the user can just hold down a button and the value will change faster and faster anyway. I could be wrong but it seems like you're trying to solve a problem that doesn't exist, or else you're trying to solve the wrong problem.
-
February 9th, 2006, 01:31 AM
#8
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
Thanks all of you. jmcilhinney,HanneSThEGreaT,aniskhan.
With warm regards,
KEDAR
-
June 9th, 2013, 04:00 PM
#9
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
Not sure if you've found a satisfying solution but try this:
if (Convert.ToInt32(<NameOfNumericUpDownObject>.Text) < <NameOfNumericUpDownObject>.Value){ /*The up arrow was pressed (Value Increased)*/
//Code Goes Here
}
else{/*Down Arrow Pressed (Value Decreaseed)*/
//Code Goes Here
}
The .Text parameter doesn't seem to have an intellisense entry but it is there, and it doesn't get updated right away so it hangs around at the previous value. By converting it to an int and comparing it to the .Value parameter, which DOES get updated immediately, you can discern whether the value has increased or decreased.
Hope this helps.
-
June 10th, 2013, 12:58 AM
#10
Re: How to check if Up/Down Button is pressed on NumericUpDown Control...
Thanks for your eagerness to help. But I suppose after 7 yaers, it is safe to assume that this thread was resolved. Please do not revive old threads. There are plenty of active threads that also need help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|