private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.NoMove2D;
int xOffset;
int yOffset;
// System.Windows.Forms.ToolTip=System.Windows.Forms.ToolTip;
if (e.Button == 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_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Changes the isMouseDown field so that the form does
// not move unless the user is pressing the left mouse button.
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.MouseUp += new MouseEventHandler(Form1_MouseUp);
}