Vertical Scroll Bar Sample


Scroll bars are explained in details in Lesson 43. There are two types of scroll bars in Visual Basic 6. They are vertical scroll bar and horizontal scroll bar which are available in the VB6 toolbox as VScrollBar and HScrollBar respectively. Both are described in Lesson 43. Both are of great use in developing a Windows program in the sense that they are one of the very common controls that are used. VScrollBar and HScrollBar - both have the same properties and features. So learning one is sufficient for the understanding of the other.

Learn about scroll bars:

This sample program shows you how to utilize the VScrollBar control in your program. There are many ways to implement this control. But when the practical implementation is the subject, you might have to make your own scroll bar control. However, having the concept of the basic control will give you an idea how it works or how it should work depending on your project.

Let me give you a brief description of the design of this sample. The PictureBox control has been taken to display information on it. The Print command prints messages on the PictureBox control. When more lines of messages are printed on PictureBox, the VScrollBar control helps you scroll down the page so that the remaining messages become visible. Here I use the term "message" to refer to text information or string value.


Learn about PictureBox:

The Move method is used in the Change event of the VSrollBar control to move the PictureBox so that it displays the rest of the messages.

Learn about events and methods:

When the form is loaded the messages are shown using the Print command. More specifically, the Print commands are executed inside the Load event of the Form object.


Learn about form events:




Screenshot:
Demonstrating the VScrollBar demo in VB6












Code:
Private Sub Form_Load()
    Form1.Show
    Picture1.Print "Welcome to VBTUTES.COM"
    Picture1.Print "You can learn about VB6 here"
    Picture1.Print "So many code samples are there"
    Picture1.Print "VB6 is amazing"
    Picture1.Print "Its powerful"
    Picture1.Print "____________"
    Picture1.Print "VB6 is interesting"
    Picture1.Print "Visual Basic is awesome"
    Picture1.Print "Visit WWW.VBTUTES.COM"
    Picture1.Print "...................."
    Picture1.Print "...................."
    Picture1.Print "----------------------"
End Sub
___________________________________________
Private Sub VScroll1_Change()
    Picture1.Move 0, -VScroll1.Value * 50
End Sub