firing numericupdown event from another function

 

and also knowing once it is fired whether it is an up click or a down click

OtherFunction()

UpDown1_DownClick(UpDown1, New System.EventArgs()) 

Dim iUpDownValue As Integer

Dim iPrevUpDownValue As Integer = 0

Private Sub UpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpDown1.ValueChanged

           iUpDownValue = UpDown1.Value

           If iUpDownValue > iPrevUpDownValue Then 'Upclick

                 Else 'Downclick

           End If

End Sub

 

Thank you,

-Greg



Answer this question

firing numericupdown event from another function

  • flash.tato

    There's a simpler solution to your problem: just make a 'Static' variable inside the ValueChanged Sub. The static variable will retain its value so the next time you enter the eventsub, you can compare the current value against the static variable to see what the change was.

  • Syed Junaid

    Thank you everyone!
  • Vhradice

    Hi,

     I had to re-read as i started thinking about mouse event arguments. As in mouse button up or down.

    To FIRE from another function use.>>

    NumericUpDown1.UpButton() ' or

    NumericUpDown1.DownButton()

     

    Anyway the following code doesn't work in the Value_Changed Sub for some unknown reason in that event it takes two clicks on a control arrow to change the textbox1 content. [EDIT : ] I've just realised the Value_Changed event is fired mostly when it is changed manually ( not with the arrow buttons ) as in Text_Changed for a textBox.

     

    Regards,

    S_DS

    __________________________________________________________________________________

     

    Dim prevValue As Double = 0

    Private Sub NumericUpDown1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NumericUpDown1.MouseDown

    Dim myNum As Double

    myNum = CDbl(NumericUpDown1.Text)

    If myNum > prevValue Then

    TextBox1.Text = "Number went up!!"

    ElseIf myNum < prevValue Then

    TextBox1.Text = "Number went down!!"

    ElseIf myNum = prevValue Then

    'You'll see this message only when you reach the MAXIMUM

    'or MINIMUM value set in the control after another click of your mouse too.

    TextBox1.Text = "Number in the control hasn't changed!!"

    End If

    prevValue = CDbl(NumericUpDown1.Text)

    End Sub

     



  • Johan Andersson

    Hi,

    Do you also need to know when the Maximum or Minimum values are reached and if the user is still clicking the mouse

    Regards,

    S_DS



  • firing numericupdown event from another function