C# 使用重载消息处理函数的方式,实现没有标题栏的窗体的拖动。

private const int WM_NCHITTEST = 0x84;

        private const int HTCLIENT = 0x1;

        private const int HTCAPTION = 0x2;

 

        protected override void WndProc(ref Message m)

        {

            switch(m.Msg)

            {

// 捕获鼠标移动的消息

                case WM_NCHITTEST:

                                       

                    base.WndProc(ref m);

                    if ((int)m.Result == HTCLIENT)

                        m.Result = (IntPtr)HTCAPTION;

                    return;

            }

            base.WndProc(ref m);

        }

你可能感兴趣的:(C#)