窗体移动
private Point mouseOffset;
private bool isMouseDown = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
int yOffset, xOffset;
if(e.Button == System.Windows.Forms.MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if(e.Button == System.Windows.Forms.MouseButtons.Left)
{
isMouseDown = false;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if(isMouseDown)
{
Point p = Control.MousePosition;
p.Offset(mouseOffset.X, mouseOffset.Y);
Location = p;
}
}
private bool isMouseDown = false;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
int yOffset, xOffset;
if(e.Button == System.Windows.Forms.MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if(e.Button == System.Windows.Forms.MouseButtons.Left)
{
isMouseDown = false;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if(isMouseDown)
{
Point p = Control.MousePosition;
p.Offset(mouseOffset.X, mouseOffset.Y);
Location = p;
}
}