A simple example of a border free form movement in C
- 2020-05-19 05:33:49
- OfStack
Start by building an Windows application
Set the FormBorderStyle property of Form1 to Noe
Point mouseOff;// Mouse moves the position variable
bool leftFlag;// Whether the flag is left key
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); // You get the value of the variable
leftFlag = true; // Click the left button to mark as true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); // Set the position after the move
Location = mouseSet;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;// Marked as after mouse release false;
}
}