Visual Basic / Visual Studio 2013 Trackbar Movement Direction

264 views Asked by At

I am writing a program that will hopefully simulate events based upon the direction of movement and the value of a trackbar. Using the value of the trackbar is easy, but I can't figure out how to determine if the user is moving it in a positive or negative direction. For example, if the user moves it from 0 to 10 I would like for a variable to equal something (1 or true preferably) and do the same if the user moved it in a negative direction. Thanks for your help!

-Doug

1

There are 1 answers

1
doug On

Thanks idle. Thank you for creating a definition for this before-unforeseen conundrum. I tried declaring a variable to hold the previous value of the trackbar, but I couldn't quite figure out how to go about it since every time the trackbar is moved the variable is changed.

Edit: Figured it out, sorry for being a noob...

Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll

    dir = TrackBar1.Value - tick

    If dir = 1 Then
        Label2.Text = "positive"
    ElseIf dir = -1 Then
        Label2.Text = "negative"
    End If
    tick = TrackBar1.Value
End Sub

End Class