Skip to content

Instantly share code, notes, and snippets.

@Mahno74
Last active July 6, 2021 10:38
Show Gist options
  • Save Mahno74/e8ff4982650e62b52d7d919b05400670 to your computer and use it in GitHub Desktop.
Save Mahno74/e8ff4982650e62b52d7d919b05400670 to your computer and use it in GitHub Desktop.
Премещение формы мышью
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
// если нажата левая кнопка мыши
if (e.Button == MouseButtons.Left)
{
moveStart = new Point(e.X, e.Y);
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
// если нажата левая кнопка мыши
if ((e.Button & MouseButtons.Left) != 0)
{
// получаем новую точку положения формы
Point deltaPos = new Point(e.X - moveStart.X, e.Y - moveStart.Y);
// устанавливаем положение формы
this.Location = new Point(this.Location.X + deltaPos.X, this.Location.Y + deltaPos.Y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment