mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-28 23:42:13 +12:00
Set hand cursor when dragging window
This commit is contained in:
parent
59ce99cb15
commit
b0024b5603
7 changed files with 77 additions and 4 deletions
20
ShareX/Properties/Resources.Designer.cs
generated
20
ShareX/Properties/Resources.Designer.cs
generated
|
@ -1071,6 +1071,16 @@ public static System.Drawing.Bitmap clock_select {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
public static byte[] closedhand {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("closedhand", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
|
@ -2263,6 +2273,16 @@ public static string OCRForm_AutoProcessing {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
public static byte[] openhand {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("openhand", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Optical character recognition feature is only available with Windows version {0} or newer..
|
||||
/// </summary>
|
||||
|
|
|
@ -1123,4 +1123,10 @@ Middle click to close</value>
|
|||
<data name="status_busy" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\status-busy.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="closedhand" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\closedhand.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="openhand" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\openhand.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
BIN
ShareX/Resources/closedhand.cur
Normal file
BIN
ShareX/Resources/closedhand.cur
Normal file
Binary file not shown.
After Width: | Height: | Size: 326 B |
BIN
ShareX/Resources/openhand.cur
Normal file
BIN
ShareX/Resources/openhand.cur
Normal file
Binary file not shown.
After Width: | Height: | Size: 326 B |
|
@ -2128,6 +2128,12 @@
|
|||
<ItemGroup>
|
||||
<None Include="Resources\status-away.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\closedhand.cur" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\openhand.cur" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
|
|
|
@ -29,6 +29,7 @@ private void InitializeComponent()
|
|||
this.Text = "ShareX - Pin to screen";
|
||||
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.PinToScreenForm_KeyUp);
|
||||
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PinToScreenForm_MouseDown);
|
||||
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PinToScreenForm_MouseMove);
|
||||
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PinToScreenForm_MouseUp);
|
||||
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.PinToScreenForm_MouseWheel);
|
||||
this.ResumeLayout(false);
|
||||
|
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.Properties;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
@ -93,8 +94,9 @@ public int ImageOpacity
|
|||
|
||||
public PinToScreenOptions Options { get; private set; }
|
||||
|
||||
private bool isDWMEnabled;
|
||||
private bool loaded;
|
||||
private bool isDWMEnabled, loaded, dragging;
|
||||
private Point initialLocation;
|
||||
private Cursor openHandCursor, closedHandCursor;
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
|
@ -117,6 +119,10 @@ private PinToScreenForm(PinToScreenOptions options)
|
|||
TopMost = Options.TopMost;
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
|
||||
|
||||
openHandCursor = Helpers.CreateCursor(Resources.openhand);
|
||||
closedHandCursor = Helpers.CreateCursor(Resources.closedhand);
|
||||
SetHandCursor(false);
|
||||
|
||||
isDWMEnabled = NativeMethods.IsDWMEnabled();
|
||||
|
||||
loaded = true;
|
||||
|
@ -144,11 +150,31 @@ protected override void Dispose(bool disposing)
|
|||
{
|
||||
components?.Dispose();
|
||||
Image?.Dispose();
|
||||
openHandCursor?.Dispose();
|
||||
closedHandCursor?.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
public void SetHandCursor(bool grabbing)
|
||||
{
|
||||
if (grabbing)
|
||||
{
|
||||
if (Cursor != closedHandCursor)
|
||||
{
|
||||
Cursor = closedHandCursor;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Cursor != openHandCursor)
|
||||
{
|
||||
Cursor = openHandCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetImage()
|
||||
{
|
||||
ImageScale = 100;
|
||||
|
@ -284,16 +310,30 @@ private void PinToScreenForm_MouseDown(object sender, MouseEventArgs e)
|
|||
}
|
||||
else
|
||||
{
|
||||
NativeMethods.ReleaseCapture();
|
||||
NativeMethods.SendMessage(Handle, (uint)WindowsMessages.NCLBUTTONDOWN, (IntPtr)WindowHitTestRegions.HTCAPTION, IntPtr.Zero);
|
||||
dragging = true;
|
||||
initialLocation = e.Location;
|
||||
SetHandCursor(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PinToScreenForm_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (dragging)
|
||||
{
|
||||
Location = new Point(Location.X + e.X - initialLocation.X, Location.Y + e.Y - initialLocation.Y);
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
private void PinToScreenForm_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
switch (e.Button)
|
||||
{
|
||||
case MouseButtons.Left:
|
||||
dragging = false;
|
||||
SetHandCursor(false);
|
||||
break;
|
||||
case MouseButtons.Right:
|
||||
Close();
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue