Results 1 to 7 of 7

Thread: NumericUpDown - up or down???

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    8

    NumericUpDown - up or down???

    Is there any way I can recognize whether I`ve clicked the upButton or the DownButton in NumericUpDown-box??

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    one way i can think of is defining a static value in value_changed event and compare it with current value.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    8
    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??

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    8
    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

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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:
    1. Static Dim original_Value as Single=0 'This is the original value you give to your numericupdown
    2.  
    3. If myNumUpDwn.Value > original_value Then
    4. Messagebox.Show("Going UP") ' or any toher code
    5. Elseif myNumUpDwn.Value< original_value Then
    6. Messagebox.Show("Going Down") 'or any other code
    7. Else
    8. Messagebox.Show("No Change") ' Any code here
    9. End if
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Question

    What about something like this:
    VB Code:
    1. Dim fPreviousValue As Single = 0
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         With NumericUpDown1
    5.             .DecimalPlaces = 1
    6.             .Increment = 0.5
    7.             .Maximum = 3
    8.             .Minimum = -1
    9.             fPreviousValue = .Value
    10.         End With
    11.     End Sub
    12.  
    13.     Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
    14.         'Determine which way the value of the control has changed
    15.         If NumericUpDown1.Value > fPreviousValue Then
    16.             lblStatus.Text = "UP"
    17.         ElseIf NumericUpDown1.Value < fPreviousValue Then
    18.             lblStatus.Text = "down"
    19.         Else
    20.             lblStatus.Text = ""
    21.         End If
    22.         fPreviousValue = NumericUpDown1.Value
    23.     End Sub
    ~Peter


  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    8

    Talking

    Hey, tanks MrGTI! That was exactly what I awas looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width