Skip to content

Commit 5d842e4

Browse files
Added Drag.cs to drag all forms.
1 parent 4080f71 commit 5d842e4

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

Form/Drag.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Windows.Forms;
4+
5+
namespace Loader
6+
{
7+
public class Drag
8+
{
9+
public const int WM_NCLBUTTONDOWN = 0xA1;
10+
public const int HT_CAPTION = 0x2;
11+
12+
[DllImport("User32.dll")]
13+
public static extern bool ReleaseCapture();
14+
15+
[DllImport("User32.dll")]
16+
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
17+
18+
public static void MakeDraggable(Form form)
19+
{
20+
form.MouseDown += (sender, e) =>
21+
{
22+
if (e.Button == MouseButtons.Left)
23+
{
24+
ReleaseCapture();
25+
SendMessage(form.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
26+
}
27+
};
28+
}
29+
}
30+
}

Form/Loader.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Reference Include="System.Xml" />
4747
</ItemGroup>
4848
<ItemGroup>
49+
<Compile Include="Drag.cs" />
4950
<Compile Include="KeyAuth.cs" />
5051
<Compile Include="Main.cs">
5152
<SubType>Form</SubType>

Form/Login.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Loader;
12
using System;
23
using System.Diagnostics;
34
using System.Net;
@@ -35,6 +36,7 @@ private void ShowResponse(string type)
3536
public Login()
3637
{
3738
InitializeComponent();
39+
Drag.MakeDraggable(this);
3840
}
3941

4042
#region Misc References

Form/Main.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Loader;
12
using System;
23
using System.Windows.Forms;
34

@@ -19,6 +20,7 @@ public partial class Main : Form
1920
public Main()
2021
{
2122
InitializeComponent();
23+
Drag.MakeDraggable(this);
2224
}
2325

2426
private void Main_Load(object sender, EventArgs e)

0 commit comments

Comments
 (0)