Saturday, 14 September 2013

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.
VB.Net ScrollBar Control

Properties of the ScrollBar Control

The following are some of the commonly used properties of the ScrollBar control:
S.NPropertyDescription
1AutoSizeGets or sets a value indicating whether the ScrollBar is automatically resized to fit its contents.
2BackColorGets or sets the background color for the control.
3ForeColorGets or sets the foreground color of the scroll bar control.
4ImeModeGets or sets the Input Method Editor (IME) mode supported by this control.
5LargeChangeGets or sets a value to be added to or subtracted from the Value property when the scroll box is moved a large distance.
6MaximumGets or sets the upper limit of values of the scrollable range.
7MinimumGets or sets the lower limit of values of the scrollable range.
8SmallChangeGets or sets the value to be added to or subtracted from the Value property when the scroll box is moved a small distance.
9ValueGets 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.NMethod Name & Description
1OnClick 
Generates the Click event.
2Select
Activates the control.

Events of the ScrollBar Control

The following are some of the commonly used events of the ScrollBar control:
S.NEventDescription
1ClickOccurs when the control is clicked.
2DoubleClickOccurs when the user double-clicks the control.
3ScrollOccurs when the control is moved.
4ValueChangedOccurs when the Value property changes, either by handling the Scroll event or programmatically.

Example

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 following window:
Scroll Bar Example

No comments:

Post a Comment