Is there any way I can recognize whether I`ve clicked the upButton or the DownButton in NumericUpDown-box??
Printable View
Is there any way I can recognize whether I`ve clicked the upButton or the DownButton in NumericUpDown-box??
one way i can think of is defining a static value in value_changed event and compare it with current value.
Quote:
Originally posted by Lunatic3
one way i can think of is defining a static value in value_changed event and compare it with current value.
I`m afraid I need a dynamic value to compare the value with :(
I got 4 different operations to choose between and I need spesificly to know whether the value changed up or down.
But I`m working on a way to locate the boxes in the form, which seems to work okay. But I also need to know where the form is on the screen. Got any tips, how to find out the forms top-position on the screen??
I solved my problem like this:
1)Add eventhandler to NumericUpDown
AddHandler numBox.ValueChanged, AddressOf NumericUpDown_ValueChanged
2)Find the exact position to the NumericUpDown-box
If ((Cursor.Position.Y - 30) < ((sender.top + Form.ActiveForm.DesktopLocation.Y) + (sender.height / 2))) Then
counter -= 1
ElseIf ((Cursor.Position.Y - 30) > ((sender.top + Form.ActiveForm.DesktopLocation.Y) + (sender.height / 2))) Then
counter += 1
End If
I am sorry about static value. I meant an Static Variable. That is a variable tat its value does not reset each time the event is fired.
put this code in change event of your numeric updown
VB Code:
Static Dim original_Value as Single=0 'This is the original value you give to your numericupdown If myNumUpDwn.Value > original_value Then Messagebox.Show("Going UP") ' or any toher code Elseif myNumUpDwn.Value< original_value Then Messagebox.Show("Going Down") 'or any other code Else Messagebox.Show("No Change") ' Any code here End if
What about something like this:VB Code:
Dim fPreviousValue As Single = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With NumericUpDown1 .DecimalPlaces = 1 .Increment = 0.5 .Maximum = 3 .Minimum = -1 fPreviousValue = .Value End With End Sub Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged 'Determine which way the value of the control has changed If NumericUpDown1.Value > fPreviousValue Then lblStatus.Text = "UP" ElseIf NumericUpDown1.Value < fPreviousValue Then lblStatus.Text = "down" Else lblStatus.Text = "" End If fPreviousValue = NumericUpDown1.Value End Sub
Hey, tanks MrGTI! That was exactly what I awas looking for. :D