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 −
|Sr.No.||Property & Description|
Gets or sets a value indicating whether the ScrollBar is automatically resized to fit its contents.
Gets or sets the background color for the control.
Gets or sets the foreground color of the scroll bar control.
Gets or sets the Input Method Editor (IME) mode supported by this control.
Gets or sets a value to be added to or subtracted from the Value property when the scroll box is moved a large distance.
Gets or sets the upper limit of values of the scrollable range.
Gets or sets the lower limit of values of the scrollable range.
Gets or sets the value to be added to or subtracted from the Value property when the scroll box is moved a small distance.
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 −
|Sr.No.||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 −
|Sr.No.||Event & Description|
Occurs when the control is clicked.
Occurs when the user double-clicks the control.
Occurs when the control is moved.
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 −