Page 1
Page 2
Listing 1
Option Explicit
'Scrollbar size with SIP shown
Const MINSCROLLSIZE = 2820
'Scrollbar size with SIP hidden
Const MAXSCROLLSIZE = 4020
Private Sub Form_Load()
'Set Scrollbar's parameters
Call setupScrollBar
End Sub
Private Sub Form_SIPChange(bSIPVisible As Boolean)
'Recalculate the scrollbar dimensions
Call setupScrollBar
End Sub
Public Sub setupScrollBar()
'Define the size of the scrollbar
If (Form1.SIPVisible = True) Then
'Set size of scrollbar
VScroll1.Height = MINSCROLLSIZE
'The maximum scroll value places bottom of frame
'at bottom of screen
VScroll1.Max = Frame1.Height - MINSCROLLSIZE
Else
'Set size of scrollbar
VScroll1.Height = MAXSCROLLSIZE
'The maximum scroll value places bottom of frame
'at bottom of screen
VScroll1.Max = Frame1.Height - MAXSCROLLSIZE
End If
'Set minimum to zero
VScroll1.Min = 0
'Set our increments to be ratio of current maximums
VScroll1.SmallChange = VScroll1.Max / 100
VScroll1.LargeChange = VScroll1.Max / 10
End Sub
Private Sub VScroll1_Change()
'On scroll bar change move the frame w/r to the form
'Frame1.Top = -VScroll1.Value
Frame1.Move 0, -VScroll1.Value
End Sub
The scrollbar is setup to have a value range from
zero to our frame's height minus the size of the scrollbar. By decreasing
the scrolling by the length of the scrollbar, the bottom of the frame
will be just visible when we reach the maximum value of the scrollbar.
If we do not perform the subtraction, the user will be able to scroll
the bottom of the form all the way up to the top of the screen. This will
leave a large white space that would be unattractive and is unnecessary.
With everything setup and ready to go, we need to
handle any scrolling. The routine VScroll1_Change performs the work of
moving the frame up as scrolling is performed. This function simply moves
the frame at the negative value of the scrollbar. As the scrollbar is
moved lower, the top of the frame moves up (and off the viewable area).
With these functions in place, we're ready to give
the form a test run. You should be able to see the scrollbar change and
scale as the SIP keyboard is shown. That's all there's to it. You can
expand on this technique by adding another dimension with a horizontal
scrollbar if you wish. You can use this technique with images to allow
users to pan around an image.
Carl Davis
Carl is currently Vice President of Technology
at Click Commerce, an industry-leading provider of private exchange software
for global manufacturers. He has over ten years of experience developing
and architecting software for a rich variety of systems-from complex embedded
machine vision algorithms in manufacturing to Enterprise scale knowledge
management systems to B2B E-Commerce Solutions. Carl's current interests
are in small footprint platforms including eVB and Java on both the PocketPC
and Palm computing platforms has released a series of PocketPC applications
from his own company (www.webcommando.com) for gamers.
Previous Page