c# button拖拽

  1. namespace xxx
  2. {  
  3.     public partial class Form1 : Form  
  4.     {  
  5.         Point p;  
  6.         public Form1()  
  7.         {  
  8.             InitializeComponent();  
  9.         }  
  10.   
  11.         private void button1_MouseDown(object sender, MouseEventArgs e)  
  12.         {  
  13.             p = e.Location;  
  14.         }  
  15.   
  16.         private void button1_MouseUp(object sender, MouseEventArgs e)  
  17.         {  
  18.             p = e.Location;  
  19.         }  
  20.   
  21.         private void button1_MouseMove(object sender, MouseEventArgs e)  
  22.         {  
  23.             if (e.Button == System.Windows.Forms.MouseButtons.Left)  
  24.               \\this.button1.Location = new Point(this.button1.Left + (e.X - p.X), this.button1.Top + (e.Y - p.Y));  
  25.               bool buttonToImgbox();
  26.         }  
  27.     }  
  28. }  

猜你喜欢

转载自blog.csdn.net/weixin_39235487/article/details/80063456