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)
            {
Control ctrl = sender as Control; isMouseLeftKeyDown = true; this.mousePointToClient = new Point(e.X + ctrl.Location.X, e.Y + ctrl.Location.Y); 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 }

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
猜你喜欢
  • 2021-05-23
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案