Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

I would suggest using a Panel instead of a picture box to display and scroll an image:

 

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!

  • 1 year later...
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...