ScrollBar Control in VB.net – Properties, Methods and Events

What is ScrollBar Control in VB.net?

A ScrollBar Control in VB.net is used to create and show vertical and horizontal scroll bars on the Windows form.

It is used when there is a lot of information in a form and we can’t see all of it.

Therefore, we used the VB.NET ScrollBar Control. In general, there are two kinds of ScrollBar: HScrollBar for horizontal scroll bars and VScrollBar for vertical scroll bars.

Let’s create a Scroll Bar in VB.net by dragging a Scroll Bar Control from the Toolbox and dropping it on the form.

ScrollBar Control in VB.net Tutorial

ScollBar Control in VB.net Properties

The following given below are some commonly used Properties of the ScrollBar Control

#ScollBar Control in VB.net PropertiesDescription
1.AutoSizeGets or sets a value indicating whether the ScrollBar is automatically resized to fit its contents.
2.BackColorGets or sets the background color for the control.
3.ForeColorGets or sets the foreground color of the scroll bar control.
4.ImeModeGets or sets the Input Method Editor (IME) mode supported by this control.
5.LargeChangeGets or sets a value to be added to or subtracted from the Value property when the scroll box is moved a large distance.
6.MaximumGets or sets the upper limit of values of the scrollable range.
7.MinimumGets or sets the lower limit of values of the scrollable range.
8.SmallChangeGets or sets the value to be added to or subtracted from the Value property when the scroll box is moved a small distance.
9.ValueGets or sets a numeric value that represents the current position of the scroll box on the scroll bar control.

ScrollBar Control in VB.net Methods

The following given below are some commonly used Methods of the ScrollBar Control.

#ScrollBar Control in VB.net MethodsDescription
1.UpdateScrollInfoIt is used to update the ScrollBar control using the Minimum, maximum, and the value of LargeChange properties.
2.OnScroll(ScrollEventArgs)It is used to raise the Scroll event in the ScrollBar Control.
3.OnEnabledChangedIt is used to raise the EnabledChanged event in the ScrollBar control.
4.SelectIt is used to activate or start the ScrollBar control.
5.OnValueChanged(EventArgs)It is used to raise the ValueChanged event in the ScrollBar control.
Methods and Descriptions of ScrollBar Control

ScrollBar Control in VB.net Events

The following given below are some commonly used Events of the ScrollBar Control in VB.net.

#ScrollBar Control in VB.net EventsDescription
1.AutoSizeChangedThe AutoSizeChanged event is found in the ScrollBar control when the value of the AutoSize property changes.
2.ScrollThe Scroll event is found when the Scroll control is moved.
3.TextChangedEventIt occurs in the ScrollBar control when the value of the text property changes.
4.ValueChangedA ValueChanged event occurs when the property of the value is changed programmatically or by a scroll event in the Scrollbar Control.
Events and Descriptions of ScrollBar Control

Let’s create a simple program to understand the use of ScrollBar Control in the VB.NET Windows Forms.

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "itsourcecode.com"  'Set the title for a Windows Form  
        Label1.Text = "Use of ScrollBar Control in Windows Form"
        Label1.ForeColor = Color.DarkBlue
        Me.AutoScroll = True
        Me.VScrollBar1.Minimum = 0
        Me.VScrollBar1.Maximum = 100
        Me.VScrollBar1.Value = 0
        Me.VScrollBar1.BackColor = Color.Blue
        Me.HScrollBar1.Minimum = 0
        Me.HScrollBar1.Maximum = 100
        Me.HScrollBar1.Value = 35
End Sub
End Class

Program Output:

ScrollBar Control in VB.net Output
ScrollBar Control Output

Summary

A VB.net ScrollBar Control is used to add Vertical and Horizontal scrolling features to a Windows Forms control that does not have a built-in scrolling feature.

In this article, we discussed How To Create a ScrollBar Control VB.net using Microsoft Visual Studio in Windows Forms at design-time as well as run-time.

After that, we saw how to use various Properties, Methods, and Events.


Leave a Comment