private Point mouseOffset;
private bool isMouseDown = false;
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
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.CaptionHeight - 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;
}
}
}