JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Getting and Setting a Scroll Bar's Current Value

You've added the scroll bars you need to a program, and set their Minimum, Maximum, SmallChange, and LargeChange properties, but you'd like to add one more touch. When your program first displays the scroll bars, you'd like them to display a default value, which is right in the middle of their range. How do you set the setting of a scroll bar?

You use the Value property to set a scroll bar's setting. You can set this value at either design time or run time, to read a scroll bar's setting while the program is running. The Value property holds values that can be in the range spanned by the values in the Minimum and Maximum properties.

Here's an example. In this case, we're setting up two scroll bars, a horizontal one and a vertical one, and placing the scroll box of each scroll bar in the center of the range when the scroll bar first appears by setting the Value properties this way:

Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    HScrollBar1.Minimum = 0
    HScrollBar1.Maximum = 100
    HScrollBar1.LargeChange = 10
    HScrollBar1.SmallChange = 1
    HScrollBar1.Value = 20
End Sub

When the user makes a change in a scroll bar, you get the new setting from the Value property when the Scroll event is triggered (see the next topic).

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor