鼠标拖动窗体功能

 1         static int cx = 0;

 2         static int cy = 0;

 3         static bool move = false;

 4 

 5         private void label1_MouseDown(object sender, MouseEventArgs e)

 6         {

 7             cx = e.X;

 8             cy = e.Y;

 9             move = true;

10         }

11         private void label1_MouseMove(object sender, MouseEventArgs e)

12         {

13             if (move)

14             {

15 

16                 this.Left += e.X - cx;

17                 this.Top += e.Y - cy;

18             }

19         }

20 

21         private void label1_MouseUp(object sender, MouseEventArgs e)

22         {

23             move = false;

24         }

你可能感兴趣的:(鼠标)