C# 无边框窗体移动代码

C# 无边框窗体移动代码

        Point _frmPoint = new Point(); //移动前窗体左上角坐标
        Point _mousePoint = new Point(); //按下鼠标时坐标
        bool move = false; //是否移动
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            _frmPoint = this.Location;
            _mousePoint.X = e.X;
            _mousePoint.Y = e.Y;
            move = true;
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!move)
                return;
            _frmPoint.X += -_mousePoint.X + e.X;
            _frmPoint.Y += -_mousePoint.Y+ e.Y;
            this.Location = _frmPoint;
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {

            move = false;
        }

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。