|
When scrollbars are visible, panning gives the user the ability to click on the background of the control and move the contents around. The Sizer control must receive the MouseDown event in order to begin Panning. In some cases, you might have a control that covers up the background. To activate panning in this case, you will need to call the StartPanning method in the MouseDown event of that control. See the example below.
Example
Run the VB Sample Project Sample 1 and follow the steps below.
- Select Dialog from the Show menu.
- Click and drag under the word "Business" in the middle-right of the window (the scrollbars must be visible for this function to work).
- Here is the code that initiates this function on the MouseDown event:
Private Sub pic_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If asizer.Panning Then
asizer.StartPanning
End If
End Sub
When scrollbars are visible and the user presses Tab to move from control to control, you will need to use panning to keep the active control visible to the user in the window. The GotFocus event for each control calls the RepositionScrollbar subroutine shown in the example below. This keeps the control to which the user has moved visible in the window.
Private Sub RepositionScrollbar(ctl As Control)
Dim left As Long, top As Long
Dim lRightEdge As Long, lLeftEdge As Long
Dim lTopEdge As Long, lBottomEdge As Long
If Not ctl.Container Is Me Then
left = ctl.left + ctl.Container.left
top = ctl.top + ctl.Container.top
Else left = ctl.left
top = ctl.top
End If
lRightEdge = left + ctl.Width + scrollwidth
If lRightEdge > asizer.ScrollPositionH + asizer.Width Then
asizer.ScrollPositionH = lRightEdge - asizer.Width
End If
lLeftEdge = left - ctl.Width
If lLeftEdge < asizer.ScrollPositionH Then
asizer.ScrollPositionH = lLeftEdge
End If
lBottomEdge = top + ctl.Height + scrollwidth
If lBottomEdge > asizer.ScrollPositionV + asizer.Height Then
asizer.ScrollPositionV = lBottomEdge - asizer.Height
End If
lTopEdge = top - scrollwidth
If lTopEdge < asizer.ScrollPositionV Then
asizer.ScrollPositionV = lTopEdge
End If
End Sub
Keywords:
|