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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…