diff --git a/Greenshot/Controls/NonJumpingPanel.cs b/Greenshot/Controls/NonJumpingPanel.cs index 51658a105..4d107da45 100644 --- a/Greenshot/Controls/NonJumpingPanel.cs +++ b/Greenshot/Controls/NonJumpingPanel.cs @@ -1,4 +1,4 @@ -/* +/* * Greenshot - a free and open source screenshot tool * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * @@ -22,33 +22,49 @@ using System.Drawing; using System.Windows.Forms; -namespace GreenshotPlugin.Controls { - /// - /// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/ - /// - public class NonJumpingPanel : Panel { - protected override Point ScrollToControl(Control activeControl) { - // Returning the current location prevents the panel from - // scrolling to the active control when the panel loses and regains focus - return DisplayRectangle.Location; - } +namespace GreenshotPlugin.Controls +{ + /// + /// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/ + /// + public class NonJumpingPanel : Panel + { + protected override Point ScrollToControl(Control activeControl) + { + // Returning the current location prevents the panel from + // scrolling to the active control when the panel loses and regains focus + return DisplayRectangle.Location; + } - /// - /// Add horizontal scrolling to the panel, when using the wheel and the shift key is pressed - /// - /// MouseEventArgs - protected override void OnMouseWheel(MouseEventArgs e) - { - if (VScroll && (ModifierKeys & Keys.Shift) == Keys.Shift) - { - VScroll = false; - base.OnMouseWheel(e); - VScroll = true; - } - else - { - base.OnMouseWheel(e); - } - } - } + /// + /// Add horizontal scrolling to the panel, when using the wheel and the shift key is pressed + /// + /// MouseEventArgs + protected override void OnMouseWheel(MouseEventArgs e) + { + //Check if Scrollbars available and CTRL key pressed -> Zoom IN OUT + if ((VScroll || HScroll) && (ModifierKeys & Keys.Control) == Keys.Control) + { + VScroll = false; + HScroll = false; + base.OnMouseWheel(e); + VScroll = true; + HScroll = true; + } + else + { + //Vertical Scoll with SHIFT key pressed + if (VScroll && (ModifierKeys & Keys.Shift) == Keys.Shift) + { + VScroll = false; + base.OnMouseWheel(e); + VScroll = true; + } + else + { + base.OnMouseWheel(e); + } + } + } + } } diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index 6e19df179..ece824bdb 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -66,6 +66,9 @@ namespace Greenshot { // whether part of the editor controls are disabled depending on selected item(s) private bool _controlsDisabledDueToConfirmable; + // Used for tracking the mouse scrollwheel changes + private DateTime _zoomStartTime = DateTime.Now; + /// /// All provided zoom values (in percents) in ascending order. /// @@ -904,11 +907,33 @@ namespace Greenshot { /// /// /// - private void PanelMouseWheel(object sender, MouseEventArgs e) { + /// + /// This is a "work-around" for the MouseWheel event which doesn't get to the panel + /// + /// + /// + private void PanelMouseWheel(object sender, MouseEventArgs e) + { + if (System.Windows.Forms.Control.ModifierKeys.Equals(Keys.Control)) + { + if (_zoomStartTime.AddMilliseconds(100) < DateTime.Now) //waiting for next zoom step 100 ms + { + _zoomStartTime = DateTime.Now; + if (e.Delta > 0) + { + ZoomInMenuItemClick(sender, e); + } + else if (e.Delta < 0) + { + ZoomOutMenuItemClick(sender, e); + } + } + + } panel1.Focus(); } - protected override bool ProcessKeyPreview(ref Message msg) { + protected override bool ProcessKeyPreview(ref Message msg) { // disable default key handling if surface has requested a lock if (!_surface.KeysLocked) { return base.ProcessKeyPreview(ref msg);