#region 设置鼠标可以移动
private bool ismouseDown = false;//判断是否按下鼠标
private Point mouseOffset;//记录鼠标坐标
private void Login_MouseDown(object sender, MouseEventArgs e)
{
int xOffset; //定义X坐标
int yOffset; //定义Y坐标
if (e.Button == MouseButtons.Left)
{ //如果鼠标的左键点击了,则将坐标分别进行相应的移动
xOffset = -e.X;
yOffset = -e.Y;
mouseOffset = new Point(xOffset, yOffset);
ismouseDown = true; //将mousedowm变量置为true,说明mousedown了
}
}
private void Login_MouseMove(object sender, MouseEventArgs e)
{
//如果鼠标移动了
if (ismouseDown)
{
//获取坐标的位置
Point MousePos = Control.MousePosition;
MousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = MousePos; //此时获取的坐标的值即为鼠标的坐标
}
}
private void Login_MouseUp(object sender, MouseEventArgs e)
{
//如果鼠标按键松开了,则将mousedown属性置为false,说明鼠标的左键已经松开
if (e.Button == MouseButtons.Left)
ismouseDown = false;
}
}
#endregion