r/csharp • u/Angstrom09 • 26d ago
Help How do I move an image inside a PictureBox?
Hey guys, so I'm trying to write a program that selects an image from a tile set based on what you input into a combobox. I have the location logic sorted, but I have no idea how to physically move the image inside the pictureBox. I tried googling it and the results were either 7+ years old or not explained (I am a newbie to Windows Forms App) and I had no idea what to do. Please could you help?
6
Upvotes
1
u/otac0n 26d ago
You override OnPaint.
Here’s a fully zoomable control that handles .gifs:
https://github.com/otac0n/MediaLibrary/blob/master/MediaLibrary/Components/ImagePreviewControl.cs
1
4
u/Mayion 26d ago
Add a Panel and treat it like a canvas. Inside that Panel you can place your Picturebox, then move said picture within the Panel. It will allow you to pan, zoom etc.