窗体程序开发过程中有时候为了界面设计的原因需要将窗体的边框去除,从而导致窗体无法正常移动。
下面的方法可以解决这个问题:
private bool _mouseisdown = false;
private Point _lastPoint = new Point();
private void plTitle_MouseDown(object sender, MouseEventArgs e)
{
_mouseisdown = true;
}
private void plTitle_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
this._lastPoint = new Point(e.X, e.Y);
return;
}
if (_mouseisdown)
{
Point newLocation = new Point();
newLocation.X = this.Location.X + e.X - _lastPoint.X;
newLocation.Y = this.Location.Y + e.Y - _lastPoint.Y;
this.Location = newLocation;
}
}
private void plTitle_MouseUp(object sender, MouseEventArgs e)
{
_mouseisdown = false;
}
还有其他方法到时候再更新