Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse a scroll bar to let the user scroll a picture vertically
DescriptionThis example shows how to use a scroll bar to let the user scroll a picture vertically in Visual Basic 6.
Keywordsscroll bar, VScrollBar, vertical, vertical scroll bar, scroll
CategoriesControls, Graphics
 
Thanks to Gamal.

The form contains a PictureBox named p1 that contains an Image control named im1. The im1 control holds the picture. The p1 control is used to clip the image so you only see that part that you should as the picture is scrolled.

When the form loads, its Load event handler calls subroutine ConfigureScrollBars to set the scroll bar's Min, Max, LargeChange, and SmallChange properties.

 
Private Sub Form_Load()
    ConfigureScrollBars
End Sub

Private Sub ConfigureScrollBars()
    If im1.Height > p1.ScaleHeight Then
        vbar.Min = 0
        vbar.Max = p1.ScaleHeight - im1.Height
        vbar.LargeChange = p1.ScaleHeight
        vbar.SmallChange = p1.ScaleHeight / 5

        im1.Top = vbar.Value
    Else
        vbar.Visible = False
    End If
End Sub
 
When the user manipulates the scroll bar, the program calls subroutine PicScrol, which simply sets the inner PictureBox's Top property.
 
Private Sub vbar_Change()
    PicScrol
End Sub

Private Sub vbar_Scroll()
    PicScrol
End Sub

Sub PicScrol()
    im1.Top = vbar.Value
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated