TrackBar in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the TrackBar control


TrackBar

The HScrollBar and VScrollBar controls let the user drag a "thumb" across the bar to select an integer value similarly to TrackBar. HScrollBar, VScrollBar, and TrackBar even have similar properties. The main difference is how these controls appear.

The two scrollbar controls have a flexible sizing, and they may seem more elegant to some users. However the TrackBar control lets the user drag a pointer to select an integer value, which is usually a more intuitive way to select a value than a NumericUpDown control (although it takes a lot more space on the form).

The TrackBar control allows you to drag a pointer along a bar to select a numeric value.

The control's Value, Minimum, Maximum, and TickFrequency properties are integer values, so the TrackBar control is not ideal for letting the user select a non-integral value such as 5.34.

Its Scroll event fires when the user changes the control's value interactively.

    Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) _
    Handles TrackBar1.Scroll
        VolumeLabel.Text = String.Format("Volume: {0}", TrackBar1.Value)
    End Sub


value

The ValueChanged event occurs when the control's value changes either because the user changed it interactively or because the program changed it with code.

    Private Sub TrackBar1_ValueChanged(sender As Object, e As EventArgs) _
    Handles TrackBar1.ValueChanged
        If TrackBar1.Value = 50 Then
            Console.WriteLine("The Volume Has Been Maxed Out!")
        Else
            Console.WriteLine("The volume has been set to: " & TrackBar1.Value)
        End If
    End Sub

Previous Lesson | Next Lesson


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.