See Also Example
Applies To
Horizontal scroll bar, vertical scroll bar
Description
Occurs while a user drags the box on a scroll bar.
Syntax
ctlname_Scroll ( )
Remarks
You can use this event to perform calculations or to manipulate controls that must be coordinated with ongoing changes in scroll bars. In contrast, use the Change event when you want an update to occur only once, after a scroll bar changes.
Note Avoid using a MsgBox statement or function in this event.
Help:
Change Event
Programmer's Guide:
Chapter 3, "Creating and Using Controls"
The example changes the size of a shape control to correspond to the value of a horizontal scroll bar as you drag the box on the scroll bar. To try this example, paste the code into the Declarations section of a form that contains a shape control, a label, and a horizontal scroll bar. Set the Index property for the Shape control to 0 (to create a control array). Then press F5 and move the scroll bar.
Sub Form_Load ()
' Move and size the first Shape control.
Shape1(0).Move HScroll1.Left, HScroll1.Top * 1.5, HScroll1.Width, HScroll1.Height
Label1.Caption = "" ' Set the Label caption.
Load Shape1(1) ' Create the second Shape.
' Move and size the second Shape control.
Shape1(1).Move Shape1(0).Left, Shape1(0).Top, 1, Shape1(0).Height
Shape1(1).BackStyle = 1 ' Set BackStyle to Opaque.
Shape1(1).Visible = True ' Display the second Shape.
HScroll1.Min = 1 ' Set Values of the Scroll bar.
HScroll1.Max = HScroll1.Width
End Sub
Sub HScroll1_Change ()
Label1.Caption = "Changed" ' Display message after change.
End Sub
Sub HScroll1_Scroll ()
Shape1(1).BackColor = &HFF0000 ' Set Shape color to Blue.
Label1.Caption = "Changing" ' Display message while scrolling.
Shape1(1).Width = HScroll1.Value ' Size Shape to Scroll Value.
End Sub