How To Use TrackBar Control VB.NET

In this article you will learn about the TrackBar control,its properties and how you can use this control.
  • 7407
 

A visual basic TrackBar control provides intuitive way to select a value from a given range by providing a scroll box and scale of value. The user can slide the scrollbar on the scale to point to the desired value. When the user moves the slider using either the mouse or the direction keys the control sends Events to indicate the change. The volume control in the windows operating systems are TrackBar control.
 
Properties of TrackBar control:-

  • Maximum:- Determines the Upper Limit of the range with which TrackBar is working.
  • Minimum:- Determines the Lower Limit of the range with which TrackBar is working. 
  • Scroll:- When either a mouse or Keyboard action moves the Scroll box. 
  • TickStyle:- Determine a value indicating how to display the Tick Marks on the TrackBar.

How to use TrackBar Control

  • Simply create a new project. 
  • Drag a TrackBar, Timer, Progress Bar, label controls on form. Form will look like below.

    TrackBar1.gif

    TrackBar2.gif
     
  • Change the class name to frmTimernTracknProgressBar and write the below code.

        Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If ProgressBar1.Value < ProgressBar1.Maximum Then
                'Increase the Progress bar Indicator
                ProgressBar1.Value += 5
            Else
                'Reset the Progress bar Indicator
                ProgressBar1.Value = ProgressBar1.Minimum
            End If
            lblmsg.Text = "Percentage Complete : " & ProgressBar1.Value & "%"
        End Sub
         Private Sub TrackBar1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
            Dim trkBar As TrackBar = CType(sender, TrackBar)
            If trkBar.Value >= 1 Then
                'Set timer value based on the Selection
                Timer1.Interval = trkBar.Value
            End If
         End Sub

    Output

    TrackBar3.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.