I enjoyed Joel Paula’s “Scrollable Viewport for a Picture” tip [“101 Tech Tips for VB Developers,” Supplementto the February 1997 issue of VBPJ, page 12], and I’d like to make some improvements to it. First, make thescrollbar’s Scroll event update the picture position so it moves while you drag the scroll box. Second, declarethese form level variables:
Dim StartX As Long, StartY As LongDim Moving As Boolean
Finally, declare these three events for PicPicture:
Private Sub PicPicture_MouseDown_ (Button As Integer, Shift As _ Integer, x As Single, y As Single) StartX = x StartY = y Moving = TrueEnd SubPrivate Sub PicPicture_MouseMove_ (Button As Integer, Shift As _ Integer, x As Single, y As Single) If Moving Then PicPicture.Move _ PicPicture.Left + x - _ StartX, PicPicture.Top + _ y - StartY End IfEnd SubPrivate Sub PicPicture_MouseUp_ (Button As Integer, Shift As _ Integer, x As Single, y As Single) Moving = FalseEnd Sub
Now you can scroll the image with your mouse. Don’t forget to test for the borders of the image.