diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index a6da5b4ed..339e4b02c 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -1890,7 +1890,7 @@ namespace Greenshot.Drawing /// /// Get the rectangle bounding the part of this Surface currently visible in the editor (in surface coordinate space). /// - private Rectangle GetVisibleRectangle() + public Rectangle GetVisibleRectangle() { var bounds = Bounds; var clientArea = Parent.ClientRectangle; diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index d5de0b5c9..ec53969f5 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -1572,8 +1572,24 @@ namespace Greenshot { } private void ZoomSetValue(int value) { + var surface = Surface as Surface; + var panel = surface?.Parent as Panel; + if (panel == null) + { + return; + } + + // Store old scroll position + var rc = surface.GetVisibleRectangle(); + var size = surface.Size; + var horizontalCenter = 1.0 * (rc.Left + rc.Width / 2) / size.Width; + var verticalCenter = 1.0 * (rc.Top + rc.Height / 2) / size.Height; + + // Set the new zoom value _zoomValue = value; Surface.ZoomFactor = 1f * value / 100; + Size = GetOptimalWindowSize(); + AlignCanvasPositionAfterResize(); // Update zoom controls string valueString = value.ToString(); @@ -1584,8 +1600,13 @@ namespace Greenshot { } } - Size = GetOptimalWindowSize(); - AlignCanvasPositionAfterResize(); + // Restore scroll position + rc = surface.GetVisibleRectangle(); + size = surface.Size; + panel.AutoScrollPosition = new Point( + (int)(horizontalCenter * size.Width) - rc.Width / 2, + (int)(verticalCenter * size.Height) - rc.Height / 2 + ); } } }