private Point mouseOffset;        //记录鼠标指针的坐标
        private bool isMouseDown = false//记录鼠标按键是否按下
 
        private void picCLose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
 
        private void fmLogin_MouseDown(object sender, MouseEventArgs e)
        {
            int xOffset;
            int yOffset;
 
            if (e.Button == MouseButtons.Left)
            {
                xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                yOffset = -e.Y - SystemInformation.CaptionHeight -
                 SystemInformation.FrameBorderSize.Height;
                mouseOffset = new Point(xOffset, yOffset);
                isMouseDown = true;
            }
        }
 
        private void fmLogin_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(mouseOffset.X+5, mouseOffset.Y+30);
                Location = mousePos;
            }
        }
 
        private void fmLogin_MouseUp(object sender, MouseEventArgs e)
        {
            // 修改鼠标状态isMouseDown的值
            // 确保只有鼠标左键按下并移动时,才移动窗体
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;
            }
        }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-05-13
  • 2021-11-27
  • 2022-12-23
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2021-11-18
  • 2021-05-20
  • 2021-07-05
  • 2021-11-06
相关资源
相似解决方案