Saturday, May 7, 2011

Horizontal and Vertical Scroll Bars



Horizontal and vertical scroll bars are widely used in Windows applications.  Scroll bars provide an intuitive way to move through a list of information and make great input devices.


Both type of scroll bars are comprised of three areas that can be clicked, or dragged, to change the scroll bar value.  Those areas are:


Clicking an end arrow increments the scroll box a small amount, clicking the bar area increments the scroll box a large amount, and dragging the scroll box (thumb) provides continuous motion.  Using the properties of scroll bars, we can completely specify how one works.  The scroll box position is the only output information from a scroll bar.

Scroll Bar Properties:

LargeChange     Increment added to or subtracted from the scroll bar Value property when the bar area is clicked.

Max                     The value of the horizontal scroll bar at the far right and the value of the vertical scroll bar at the bottom.  Can range from -32,768 to 32,767.

Min                      The other extreme value - the horizontal scroll bar at the left and the vertical scroll bar at the top.  Can range from -32,768 to 32,767.

SmallChange    The increment added to or subtracted from the scroll bar Value property when either of the scroll arrows is clicked.

Value                  The current position of the scroll box (thumb) within the scroll bar.  If you set this in code, Visual Basic moves the scroll box to the proper position.



Properties for horizontal scroll bar:


Properties for vertical scroll bar:



A couple of important notes about scroll bars:

Note that although the extreme values are called Min and Max, they do not necessarily represent minimum and maximum values.  There is nothing to keep the Min value from being greater than the Max value.  In fact, with vertical scroll bars, this is the usual case.  Visual Basic automatically adjusts the sign on the SmallChange and LargeChange properties to insure proper movement of the scroll box from one extreme to the other.



.

If you ever change the Value, Min, or Max properties in code, make sure Value is at all times between Min and Max or and the program will stop with an error message.

Scroll Bar Events:

Change         Event is triggered after the scroll box's position has been modified.  Use this event to retrieve the Value property after any changes in the scroll bar.
Scroll              Event triggered continuously whenever the scroll box is being moved.





No comments:

Post a Comment