Skip to content

Instantly share code, notes, and snippets.

@AnshulKuthiala
Created December 10, 2018 18:28
Show Gist options
  • Save AnshulKuthiala/95cc8b3268bda569fffb76e1a490ffa5 to your computer and use it in GitHub Desktop.
Save AnshulKuthiala/95cc8b3268bda569fffb76e1a490ffa5 to your computer and use it in GitHub Desktop.
[Move Form] Ability to move form using any component. Useful when form does not have a border.
private bool MouseDown { get; set; }
private System.Drawing.Point LastLocation { get; set; }
private void labelGetId_MouseDown(object sender, MouseEventArgs e)
{
MouseDown = true;
LastLocation = e.Location;
}
private void labelGetId_MouseMove(object sender, MouseEventArgs e)
{
if (MouseDown)
{
this.Location = new System.Drawing.Point(
(this.Location.X - LastLocation.X) + e.X, (this.Location.Y - LastLocation.Y) + e.Y);
this.Update();
}
}
private void labelGetId_MouseUp(object sender, MouseEventArgs e)
{
MouseDown = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment