Programming/C#
C# 마우스로 Button 움직이기
분노의블로그
2024. 8. 13. 09:28
반응형
private void button5_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Button bt = sender as Button;
int x = 0, y = 0;
if (bt.Location.X + e.X < 0)
x = 0;
else if (bt.Location.X + e.X > this.Width)
x = this.Width - bt.Width;
else
x = bt.Location.X + e.X;
if (bt.Location.Y + e.Y < 0)
y = 0;
else if (bt.Location.Y + e.Y > this.Height)
y = this.Height - bt.Height;
else
y = bt.Location.Y + e.Y;
bt.Location = new Point(x, y);
}
}
button의 MouseMove이벤트를 추가
반응형