VB6 Tutorial 43: Scrollbars

By | 2018-04-27

In this lesson, you’ll learn the basics of how to work with a scrollbar.

You have seen scroll bars in most of the Windows applications. A scroll bar is a very important element of a software. When you’ll work on a software project in VB6, you’ll need these controls if you have to scroll down or scroll up a page.

The scrollbar actually comes in two flavors or styles: vertical or horizontal. Both styles have the same properties and events. The only difference is the appearance of each on the screen.

All items discussed here apply to both styles of scrollbar.

Useful properties

The main properties of both the scroll bars are Min, Max, SmallChange, LargeChange and Value.

Vertical scroll bar

Here is the anatomy of a typical scroll bar:

Properties

There are five basic properties that you will likely work with the most. We’ll touch on each of them here.

Value

The Value property returns the scroll bar position’s value. Each position of the thumb has a value. The Value changes when you click on one of the arrow buttons or when you move the thumb by dragging it.

Min

The Min property sets/returns the minimum value of a scroll bar position.

Max

The Max property sets/returns the maximum value of a scroll bar position.

SmallChange

The SmallChange property sets/returns the amount of change to Value property in a scroll bar when the user clicks on a scroll arrow button./

LargeChange

The LargeChange property sets/returns the amount of change to Value property in a scroll bar when the user clicks on the scroll bar area.

Change Event

Not a property, the Change event fires when an arrow button or the scroll bar area is clicked or after the thumb has been dragged. The Scroll event is raised when the thumb is being dragged.

There is an example project attached to this lesson, a simple length converter for inches and centimeters. Check it out.

Challenge

Using the example project, see if you can add other units of measurement, such as gallons to liters, or perhaps miles to kilometers.

QuickHint:

In some cases, you do not need to use scroll bars as many controls in VB6 provide a scroll bar with them. For example, the TextBox control has a scroll bar with it, and it becomes enabled when you set the Multi-Line property of the TextBox control to True.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.