Move forms that have no border style
Description: This Code Snippet show how to mode a form that does not have a FormBorderStyle, or make it possible to move form without having to drag mouse on the topbar of a form.
this Excample uses a GroupPanel. You need to modify this to a component on your form.
Link: http://www.codekeep.net/snippets/f1f2b430-381b-4b6b-ad7c-1bb98416bc15.aspx
aiGroupPanel1.MouseDown += new MouseEventHandler(MouseDown);
aiGroupPanel1.MouseMove += new MouseEventHandler(MouseMove);
aiGroupPanel1.MouseUp += new MouseEventHandler(MouseUp);
}
void MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
void MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
void MouseDown(object sender, MouseEventArgs e)
{
int xOffset;
int yOffset;
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;
}
}






