Last active
July 6, 2021 10:38
-
-
Save Mahno74/e8ff4982650e62b52d7d919b05400670 to your computer and use it in GitHub Desktop.
Премещение формы мышью
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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