Home > other >  How to check if track bar value increased or decreased in vb.net 2015
How to check if track bar value increased or decreased in vb.net 2015

Time:12-21

I have a track bar in vb.net 2015,I need to know if it's value has been decreased or in increased on scrolling.

CodePudding user response:

Keep a variable which keeps track of the last value, then compare in the Scroll event, and update the variable to the new value

Private lastValue As Integer

Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
    Dim change = TrackBar1.Value - lastValue
    If change > 0 Then ' increasing

    ElseIf change < 0 ' decreasing

    Else ' stayed the same
    
    End If
    lastValue = TrackBar1.Value
End Sub

CodePudding user response:

You could add a handler on the TrackBar.ValueChanged Event. This may be sufficient for your needs if you don't care about the previous value. The difference with the Scroll event:

Occurs when the Value property of a track bar changes, either by movement of the scroll box or by manipulation in code.

  • Related