C#运行时鼠标移动控件 - 调用Windows API(ReleaseCapture)

Posted MoChiu程序人生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#运行时鼠标移动控件 - 调用Windows API(ReleaseCapture)相关的知识,希望对你有一定的参考价值。

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern bool ReleaseCapture();

        private void MoveControl(Control sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && e.Clicks == 1)
            {
                ReleaseCapture();
                SendMessage(sender.Handle, 161, 2, 0);
                SendMessage(sender.Handle, 0x0202, 0, 0);
            }
            else
            {
                //添加双击或右击代码……
            }
        }

        private void button3_MouseDown(object sender, MouseEventArgs e)
        {
            MoveControl(sender as Control, e);
        }

 

以上是关于C#运行时鼠标移动控件 - 调用Windows API(ReleaseCapture)的主要内容,如果未能解决你的问题,请参考以下文章