Picturebox scrollbars

archer_coal

Regular
Joined
Apr 4, 2003
Messages
96
has anyone added scrollbars to a picturebox in Vb.NET?
Ive done it in vb6 but some of the properties have changed or been done away with. The basic idea was using 2 pictureboxes and have the scrollbars scale using the negative value of one compared to the other.

Any tutorials, guidence or tips would be appreciated.
Thanks
 
I would suggest using a Panel instead of a picture box to display and scroll an image:

Visual Basic:
Dim myBMP as Bitmap = New Bitmap("C:\myImage.jpg") 'load the Image

Panel1.Size = New Size(500, 400) 'your panels default size...

'when the Image is smaller than the Panels size decrease the
'Panels size so there is no tileing...
If myBMP.Width < Panel1.Width Then
   Panel1.Width = myBMP.Width
End If
If myBMP.Height < Panel1.Height Then
   Panel1.Height = myBMP.Height
End If


Panel1.BackgroundImage = myBMP 'Display the image
Panel1.AutoScroll = True 'enable scrolling..
Panel1.AutoScrollMinSize = Panel1.BackgroundImage.Size

I hope this is gonna help you!
 
An update for this post.

Thanks Hamburger1984, this works great.
Just to add an additional note, for multiple image files, the routine has a memory leak.

The fix should be before you try to load up the new image, make sure you dispose of the previous one.

If Not Panel1.BackgroundImage is nothing then
Panel1.BackgroundImage.Dispose()
End If
 
Back
Top