Scroll Event

See Also5799PH5              Example5TBEBG>Low

Applies To

Horizontal scroll bar1JSJOS7, vertical scroll bar1JSJOS7.


Occurs while a user drags the box on a scroll bar.


ctlname_Scroll ( )


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 Change8DZUNR 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.


See Also


Change Event8DZUNR


Programmer's Guide:

Chapter 3, "Creating and Using Controls"

Scroll Event Example

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