HScrollBar in Visual Basic .NET
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This lesson describes the HScrollBar control
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 HScrollBar control is a horizontal scrollbar.
It has Minimum, Maximum, and Value properties. The Minimum and Maximum properties determine the range of values that the control can display, while Value property gets and sets its current numeric value. You can set these values in the Properties window or programmatically.
HScrollBar1.Maximum = 2050 HScrollBar1.Minimum = 1960 HScrollBar1.Value = 2014
The control's SmallChange property determines how much the control's Value property changes when the user clicks a scroll arrow or presses an arrow key.
The Scroll event fires when the user changes the control's value interactively:
Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) _ Handles HScrollBar1.Scroll YearLabel.Text = HScrollBar1.Value.ToString() End Sub
Previous Lesson | Next Lesson