建立一个windows窗体,名字为login,把下面方法加进代码
#region 拖动方法
int LeftTolerance = 0;int TopTolerance = 0;
Point formLocation = new Point(0, 0);
private void Login_MouseDown(object sender, MouseEventArgs e)
{
LeftTolerance = Cursor.Position.X - this.Location.X;
TopTolerance = Cursor.Position.Y - this.Location.Y;
this.Cursor = Cursors.SizeAll;
}
private void Login_MouseMove(object sender, MouseEventArgs e)
{
//拖动中
if (e.Button == MouseButtons.Left)
{
formLocation.X = Cursor.Position.X - LeftTolerance;
formLocation.Y = Cursor.Position.Y - TopTolerance;
this.Location = formLocation;
}
}
private void Login_MouseUp(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.Default;
}
#endregion