I need an event that happens when the up arrow is pressed and another when the down arrow is pressed. is there an event handler for this? all I can find is valuechanged?
Asked
Active
Viewed 1,911 times
4
-
1Asking a question like this in general doesnt make any sense... – user3596113 Feb 12 '15 at 09:32
-
1Can you store the previous value and when the value changes work out if it was an increase? – Andrew Morton Feb 12 '15 at 09:33
3 Answers
3
The short answer is no, there is no such event.
However it would be easy to check if it is an increase or decrease in value. For example if you bind the numericupdown
's value to a property in your view model, you could do it like this:
private int upDownValue;
public int UpDownValue
{
get{ return this.upDownValue; }
set
{
if(value > this.upDownValue)
{
//It increased
}
if(value < this.upDownValue)
{
//It decreased
}
this.upDownValue = value;
}
}

Klaus Byskov Pedersen
- 117,245
- 29
- 183
- 222
-
Hi im new to programming, i dont really understand whats going on here, what do you mean by view model? – john Feb 12 '15 at 10:16
-
1@john there is no short answer to what view model means. It's part of a design pattern called [Model-View-ViewModel](https://msdn.microsoft.com/en-us/magazine/dd419663.aspx) that is often used when making UI applications. Check the link and learn about it if you are interested. – Klaus Byskov Pedersen Feb 12 '15 at 10:29
-
I edited a post below that seems to work for me, thanks anyway I will look into that – john Feb 12 '15 at 10:33
1
Decimal OldValue;
private void NumericUpDown1_Click(Object sender, EventArgs e) {
if (NumericUpDown1.Value>OldValue)
{
///value increased, handle accordingly
}
else if (NumericUpDown1.Value<OldValue)
{
///value decreased, handle accordingly
}
else
{
return;
}
OldValue=NumericUpDown1.Value;
}
0
If you use the NumericUpDown from Mahapps framework you can use the ValueIncremented and ValueDecremented events.

snowrunner
- 17
- 5