Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language:
Expertise: Intermediate
Aug 1, 1997

Better Scrolling Images

I enjoyed Joel Paula's "Scrollable Viewport for a Picture" tip ["101 Tech Tips for VB Developers," Supplement to the February 1997 issue of VBPJ, page 12], and I'd like to make some improvements to it. First, make the scrollbar's Scroll event update the picture position so it moves while you drag the scroll box. Second, declare these form level variables:
 
Dim StartX As Long, StartY As Long
Dim 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 = True
End Sub

Private 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 If
End Sub

Private Sub PicPicture_MouseUp_
        (Button As Integer, Shift As _
        Integer, x As Single, y As Single)
                Moving = False
End Sub
Now you can scroll the image with your mouse. Don't forget to test for the borders of the image.
Pedro Prospero
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date