讓普通控件擁有左鍵移動窗體的功能

如題,代碼以下:orm

        /// <summary>設置能夠鼠標左鍵讓窗體移動的控件
        /// </summary>
        /// <param name="form">待移動的窗體,一般是設置了FormBorderStyle = FormBorderStyle.None的窗體</param>
        /// <param name="control">能控制窗體左鍵移動的控件</param>
        public static void SetMoveFormControl(Form form, Control control)
        {
            control.MouseDown += (s, e) =>
            {
                ReleaseCapture();
                SendMessageA((int)form.Handle, 0xa1, 2, 0);
            };
        }
        [DllImport("user32.dll")]
        private static extern int ReleaseCapture();
        [DllImport("user32.dll")]
        private static extern int SendMessageA(int hwnd, int wMsg, int wParam, int lParam);
相關文章
相關標籤/搜索