VB.Net - ScrollBar Control
The ScrollBar controls display vertical and horizontal scroll bars on the form. This is used for navigating through large amount of information. There are two types of scroll bar controls: HScrollBar for horizontal scroll bars and VScrollBar for vertical scroll bars. These are used independently from each other.
Let's click on HScrollBar control and VScrollBar control from the Toolbox and place them on the form.
Properties of the ScrollBar Control
The following are some of the commonly used properties of the ScrollBar control:
|1||AutoSize||Gets or sets a value indicating whether the ScrollBar is automatically resized to fit its contents.|
|2||BackColor||Gets or sets the background color for the control.|
|3||ForeColor||Gets or sets the foreground color of the scroll bar control.|
|4||ImeMode||Gets or sets the Input Method Editor (IME) mode supported by this control.|
|5||LargeChange||Gets or sets a value to be added to or subtracted from the Value property when the scroll box is moved a large distance.|
|6||Maximum||Gets or sets the upper limit of values of the scrollable range.|
|7||Minimum||Gets or sets the lower limit of values of the scrollable range.|
|8||SmallChange||Gets or sets the value to be added to or subtracted from the Value property when the scroll box is moved a small distance.|
|9||Value||Gets or sets a numeric value that represents the current position of the scroll box on the scroll bar control.|
Methods of the ScrollBar Control
The following are some of the commonly used methods of the ScrollBar control:
|S.N||Method Name & Description|
Generates the Click event.
Activates the control.
Events of the ScrollBar Control
The following are some of the commonly used events of the ScrollBar control:
|1||Click||Occurs when the control is clicked.|
|2||DoubleClick||Occurs when the user double-clicks the control.|
|3||Scroll||Occurs when the control is moved.|
|4||ValueChanged||Occurs when the Value property changes, either by handling the Scroll event or programmatically.|
In this example, let us create two scroll bars at runtime. Let's double click on the Form and put the follow code in the opened window.
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) _ Handles MyBase.Load 'create two scroll bars Dim hs As HScrollBar Dim vs As VScrollBar hs = New HScrollBar() vs = New VScrollBar() 'set properties hs.Location = New Point(10, 200) hs.Size = New Size(175, 15) hs.Value = 50 vs.Location = New Point(200, 30) vs.Size = New Size(15, 175) hs.Value = 50 'adding the scroll bars to the form Me.Controls.Add(hs) Me.Controls.Add(vs) ' Set the caption bar text of the form. Me.Text = "tutorialspoint.com" End Sub End Class
When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window: