mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-04 22:21:23 +12:00
Allow dragging menu using toolstrip grip
This commit is contained in:
parent
ca1d2b6e38
commit
4d515d2a9e
|
@ -24,12 +24,15 @@
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.HelpersLib
|
namespace ShareX.HelpersLib
|
||||||
{
|
{
|
||||||
public class ToolStripEx : ToolStrip
|
public class ToolStripEx : ToolStrip
|
||||||
{
|
{
|
||||||
|
public event MouseEventHandler GripMouseDown;
|
||||||
|
|
||||||
private bool clickThrough = false;
|
private bool clickThrough = false;
|
||||||
|
|
||||||
public bool ClickThrough
|
public bool ClickThrough
|
||||||
|
@ -53,5 +56,25 @@ protected override void WndProc(ref Message m)
|
||||||
m.Result = (IntPtr)NativeMethods.MA_ACTIVATE;
|
m.Result = (IntPtr)NativeMethods.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -86,5 +86,6 @@ public static partial class NativeMethods
|
||||||
public const uint MA_ACTIVATEANDEAT = 2;
|
public const uint MA_ACTIVATEANDEAT = 2;
|
||||||
public const uint MA_NOACTIVATE = 3;
|
public const uint MA_NOACTIVATE = 3;
|
||||||
public const uint MA_NOACTIVATEANDEAT = 4;
|
public const uint MA_NOACTIVATEANDEAT = 4;
|
||||||
|
public const uint MOUSE_MOVE = 0xF012;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -51,6 +51,9 @@ public static partial class NativeMethods
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern IntPtr CopyIcon(IntPtr hIcon);
|
public static extern IntPtr CopyIcon(IntPtr hIcon);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern IntPtr DefWindowProc(IntPtr hWnd, uint uMsg, UIntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool DestroyIcon(IntPtr hIcon);
|
public static extern bool DestroyIcon(IntPtr hIcon);
|
||||||
|
@ -194,6 +197,9 @@ public static partial class NativeMethods
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern bool ReleaseCapture();
|
public static extern bool ReleaseCapture();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern bool ReleaseCapture(IntPtr hwnd);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,12 @@ private void CreateMenu()
|
||||||
Text = "ToolStrip"
|
Text = "ToolStrip"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tsMain.GripMouseDown += (sender, e) =>
|
||||||
|
{
|
||||||
|
NativeMethods.ReleaseCapture(tsMain.Handle);
|
||||||
|
NativeMethods.DefWindowProc(menuForm.Handle, (uint)WindowsMessages.SYSCOMMAND, (UIntPtr)NativeMethods.MOUSE_MOVE, IntPtr.Zero);
|
||||||
|
};
|
||||||
|
|
||||||
tsMain.SuspendLayout();
|
tsMain.SuspendLayout();
|
||||||
|
|
||||||
menuForm.Controls.Add(tsMain);
|
menuForm.Controls.Add(tsMain);
|
||||||
|
@ -496,7 +502,7 @@ private void CreateMenu()
|
||||||
AnnotationOptions.BorderColor = dialogColor.NewColor;
|
AnnotationOptions.BorderColor = dialogColor.NewColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateContextMenu();
|
UpdateMenu();
|
||||||
UpdateCurrentShape();
|
UpdateCurrentShape();
|
||||||
UpdateCursor();
|
UpdateCursor();
|
||||||
}
|
}
|
||||||
|
@ -572,7 +578,7 @@ private void CreateMenu()
|
||||||
AnnotationOptions.FillColor = dialogColor.NewColor;
|
AnnotationOptions.FillColor = dialogColor.NewColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateContextMenu();
|
UpdateMenu();
|
||||||
UpdateCurrentShape();
|
UpdateCurrentShape();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -632,7 +638,7 @@ private void CreateMenu()
|
||||||
if (dialogColor.ShowDialog() == DialogResult.OK)
|
if (dialogColor.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
AnnotationOptions.HighlightColor = dialogColor.NewColor;
|
AnnotationOptions.HighlightColor = dialogColor.NewColor;
|
||||||
UpdateContextMenu();
|
UpdateMenu();
|
||||||
UpdateCurrentShape();
|
UpdateCurrentShape();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -780,14 +786,14 @@ private void CreateMenu()
|
||||||
|
|
||||||
menuForm.Show(form);
|
menuForm.Show(form);
|
||||||
|
|
||||||
UpdateContextMenu();
|
UpdateMenu();
|
||||||
|
|
||||||
CurrentShapeTypeChanged += shapeType => UpdateContextMenu();
|
CurrentShapeTypeChanged += shapeType => UpdateMenu();
|
||||||
|
|
||||||
CurrentShapeChanged += shape => UpdateContextMenu();
|
CurrentShapeChanged += shape => UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateContextMenu()
|
private void UpdateMenu()
|
||||||
{
|
{
|
||||||
if (menuForm == null) return;
|
if (menuForm == null) return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue