需要用到鼠标的按下与移动事件;、
当按下左键时,将获取当前位置。再移动进行坐标位置运算
int pLeft = 0;
int pTop = 0;
private void mouseRightForm_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button.ToString().Equals("Left"))
{
//this指的是主窗口生成的对象
this.Left = this.Location.X + e.X - pLeft;
this.Top = this.Location.Y + e.Y - pTop;
}
}
private void mouseRightForm_MouseDown(object sender, MouseEventArgs e)
{
pLeft = e.X;
pTop = e.Y;
}