曾玉锋 发表于 2013-3-18 14:54
给你个提示:获取或者设置窗体的当前位置 this.Location=new Point(x坐标,y坐标);
用Mous ...
private bool isMouseDown = false;
private Point FormLocation; //form的location
private Point mouseOffset; //鼠标的按下位置
private void Messages_MouseDown(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = true;
FormLocation = this.Location;
mouseOffset = Control.MousePosition;
}
}
catch (Exception)
{
}
}
private void Messages_MouseMove(object sender, MouseEventArgs e)
{
try
{
int _x = 0;
int _y = 0;
if (isMouseDown)
{
Point pt = Control.MousePosition;
_x = mouseOffset.X - pt.X;
_y = mouseOffset.Y - pt.Y;
this.Location = new Point(FormLocation.X - _x, FormLocation.Y - _y);
}
}
catch (Exception )
{
}
}
private void Messages_MouseUp(object sender, MouseEventArgs e)
{
try
{
isMouseDown = false;
}
catch (Exception)
{
}
}
|