Is there a simple and functional way to zoom an image in a picturebox including scroll bars?
At the moment, I use a picture box in a panel with auto scroll activated. To zoom, I enlarge the picturebox and move it with the scroll bars on the panel. The problem is, that it behaves strange. For example: If you zoom in to far, the margin between the upper and left form border and the image get's bigger and bigger.
That's the zooming method. I got it from here.
private void ZoomInOut(bool zoom)
{
//Zoom ratio by which the images will be zoomed by default
int zoomRatio = 10;
//Set the zoomed width and height
int widthZoom = pictureBox_viewer.Width * zoomRatio / 100;
int heightZoom = pictureBox_viewer.Height * zoomRatio / 100;
//zoom = true --> zoom in
//zoom = false --> zoom out
if (!zoom)
{
widthZoom *= -1;
heightZoom *= -1;
}
//Add the width and height to the picture box dimensions
pictureBox_viewer.Width += widthZoom;
pictureBox_viewer.Height += heightZoom;
}
Any help is appreciated.
Thanks in advance.
Marco
EDIT: Two screenshots of an unzoomed and a zoomed (16 times) image. Pay attention to the margin between the upper border of the image and the upper border of the form.
Top
andLeft
of yourPictureBox
. You should check the whole code yourself of post it here. – ZolliePictureBox
, yourPanel
. – Zolliezooming
code doesn't change the location ofPictureBox
, so with all that code, it shouldn't change the distance between theTop border
of yourPictureBox
and theTop border
of yourPanel
. – Zollieprivate void Form1_Resize(object sender, EventArgs e) {pictureBox_viewer.Size = panel_viewer.Size; if (viewerSize != Size.Empty) {viewerSize = pictureBox_viewer.Size;} }
It's for fitting the pictureBox to the panel when resizing the form. – BlenheimPictureBox
anchored to thePanel
? Using theAnchor
parameter?Dock
? Perhaps this is happening because it's trying to respect one of those. – Marjoriemarjory