In menu form handle esc press

This commit is contained in:
Jaex 2016-10-05 22:32:01 +03:00
parent 407b8e231c
commit 48f4ec9056
2 changed files with 10 additions and 23 deletions

View file

@ -24,15 +24,13 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ShareX.HelpersLib
{
// https://blogs.msdn.microsoft.com/rickbrew/2006/01/09/how-to-enable-click-through-for-net-2-0-toolstrip-and-menustrip/
public class ToolStripEx : ToolStrip
{
public event MouseEventHandler GripMouseDown;
private bool clickThrough = false;
public bool ClickThrough
@ -56,25 +54,5 @@ protected override void WndProc(ref Message m)
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
protected override void OnMouseDown(MouseEventArgs mea)
{
if (GripRectangle.Offset(2).Contains(mea.Location))
{
OnGripMouseDown(mea);
}
else
{
base.OnMouseDown(mea);
}
}
protected virtual void OnGripMouseDown(MouseEventArgs mea)
{
if (GripMouseDown != null)
{
GripMouseDown(this, mea);
}
}
}
}

View file

@ -63,6 +63,7 @@ private void CreateMenu()
TopMost = true
};
menuForm.KeyUp += MenuForm_KeyUp;
menuForm.LocationChanged += MenuForm_LocationChanged;
menuForm.SuspendLayout();
@ -656,6 +657,14 @@ private void CreateMenu()
form.Activate();
}
private void MenuForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Escape)
{
form.Close();
}
}
private void MenuForm_LocationChanged(object sender, EventArgs e)
{
Rectangle rectMenu = menuForm.Bounds;