devxlogo

Better Scrolling Images

Better Scrolling Images

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.

See also  Monetize TikTok For Your Business
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist