private bool isMouseLeftKeyDown = false;
        private Point mousePointToClient = new Point();//相对于本窗体鼠标位置
        private Point mousePointToScreen = new Point();//相对于屏幕鼠标位置

        private void Form_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseLeftKeyDown = true;
                this.mousePointToClient = e.Location;
                this.mousePointToScreen = Control.MousePosition;
            }
        }

        private void Form_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && isMouseLeftKeyDown)
            {
                this.Top = Control.MousePosition.Y - mousePointToClient.Y;
                this.Left = Control.MousePosition.X - mousePointToClient.X;
            }
        }

        private void Form_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseLeftKeyDown = false;
                FormClick();
            }
        }

        private void FormClick()
        {
            //鼠标位置没有发成偏移,视为点击事件
            if (mousePointToScreen != Control.MousePosition)
                return;

            //todo
        }

  

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。