C# WinForm 窗体/控件移动

   #region 窗体移动
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
        private static extern void ReleaseCapture();
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage")]
        private static extern void SendMessage(int hwnd, int wMsg, int wParam, int lParam);
        public static void WinControl_MouseDown(this Control c, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (c is Form)
                {
                    Form f = (Form)c;
                    if (f.WindowState != FormWindowState.Normal)
                    {
                        return;
                    }
                }
                ReleaseCapture();
                SendMessage((int)c.Handle, 0xA1, 2, 0);

            }
        }
        #endregion 窗体移动

 

posted @ 2022-02-18 16:02  LuoCore  阅读(386)  评论(0编辑  收藏  举报