winform 窗口点击窗体任意位置移动窗体

        private bool _isDown;
        private Point _mousePoint;
        private void Users_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) _isDown = true;
            _mousePoint = new Point(-e.X, -e.Y);
        }

        private void Users_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) _isDown = false;
        }

        private void Users_MouseMove(object sender, MouseEventArgs e)
        {
            if (!_isDown) return;
            var wz = Control.MousePosition;
            wz.Offset(_mousePoint);
            Location = wz;
        }

 

posted @ 2016-03-16 22:20  Gensir  阅读(799)  评论(0编辑  收藏  举报