r/visualbasic • u/vmevets • Dec 12 '22
VB.NET Help Zoom and Pan Picture Box
Hi all, I just picked up VB a few days back to make a form which reads in a video frame into a picture box. I would like to zoom and pan just the image (and not the picture box) using mouse scroll and left click + drag event. There doesn’t seem to be a straightforward way to even zoom in on an image let alone pan it. I put together a mouse scroll event function but it’s very convoluted and bugs out. Is there a more elegant way to approach this or if I’m missing something trivial? Thanks!
4
Upvotes
3
u/vmevets Dec 12 '22
To help others out, this is what I did;
Placed a PictureBox1 within a Panel1. Set the Panel1 AutoScroll to 'True'. The PictureBox1 SizeMode is set to 'Zoom'.
The following code lets you zoom and pan using horizontal and vertical scroll bars when the scroll mouse and ctrl key is engaged:
2
u/jd31068 Dec 12 '22
Telerik has a control that can do it https://www.telerik.com/products/winforms/picturebox.aspx
It seems you may have seen this already https://www.codeguru.com/dotnet/creating-a-picture-panning-control-in-net/
This video zooms an image with picturebox, it is in C# but you can pretty easily convert the code over. https://www.youtube.com/watch?v=VZuS6qJs58k
1
u/jcunews1 VB.Net Intermediate Dec 12 '22
You'll have to manually draw the image yourself.
Image zooming requires you to manually draw a scaled image from an image resource.
Image panning means that, only partial the image is displayed. So you code must manually draw the partial image from an image resource.
1
u/chacham2 Dec 12 '22
I'm still playing with OpenAI's gptchatbot. I posted:
It responded: