Notice
Recent Posts
Recent Comments
분노의 챔질
C# 마우스로 Button 움직이기 본문
반응형
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이벤트를 추가
반응형
'Programming > C#' 카테고리의 다른 글
C# 컨트롤 동적 생성 (0) | 2024.08.13 |
---|---|
C# 레지스트리 읽기 쓰기 (0) | 2024.08.13 |
C# ini File 읽기/쓰기 (0) | 2024.05.28 |
C# Log파일 (0) | 2024.05.28 |
C# delegate (0) | 2024.05.28 |