Shuxia Ning
2024-08-28 1a8a81785470302fc7fbd6914a9df5d1094dac2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Runtime.InteropServices;
 
namespace IStation.Win
{
    /// <summary>
    /// FORM窗体拓展类
    /// </summary>
    public static class FormExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="wMsg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
 
        private const int VM_NCLBUTTONDOWN = 0X00A1;//定义鼠标左键按下
        private const int HTCAPTION = 2;
 
        /// <summary>
        /// 拖动移动
        /// </summary>
        /// <param name="frm"></param>
        public static void DragMove(this Form frm)
        {
            //为当前应用程序释放鼠标捕获
            ReleaseCapture();
            //发送消息 让系统误以为在标题栏上按下鼠标
            SendMessage(frm.Handle, VM_NCLBUTTONDOWN, HTCAPTION, 0);
        }
 
 
 
    }
}