1、实现了控件自由拖动
  
  2、实现了控件的拖动创建,右键删除等类似IDE的控件创建,当然更多功能靠大家自己完善


  3、实现属性框与控件的绑定,可以在运行期修改控件的Text...

 

  以下是部分代码

 

 

 

view plaincopy to clipboardprint?
  1. private void button2_Click(object sender, EventArgs e)   
  2. {   
  3.     //控件框的显示与隐藏   
  4.     if (panel1.Visible == true)   
  5.     {   
  6.         button2.Text = "+  控件框";   
  7.         panel1.Visible = false;   
  8.     }   
  9.     else  
  10.     {   
  11.         button2.Text = "-  控件框";   
  12.         panel1.Visible = true;   
  13.     }   
  14. }  

 

 

 

view plaincopy to clipboardprint?
  1. private void button3_MouseDown(object sender, MouseEventArgs e)   
  2. {   
  3.     //判断鼠标左键按下   
  4.     if (e.Button == MouseButtons.Left)   
  5.     {   
  6.         Button btn = (Button)(sender);   
  7.         //初始化拖放操作。   
  8.         btn.DoDragDrop(btn, DragDropEffects.Copy);   
  9.     }   
  10. }   
  11.   
  12. private void panel4_DragDrop(object sender, DragEventArgs e)   
  13. {   
  14.     //开始拖动   
  15.     Button btn = (Button)(e.Data.GetData("System.Windows.Forms.Button"));   
  16.     Button btn_new = new Button();   
  17.     btn_new.ContextMenuStrip = contextMenuStrip1;   
  18.     btn_new.Name = btn_new.Text = btn.Text + "--" + name;   
  19.     btn_new.Left = PointToClient(MousePosition).X-panel4.Left;   
  20.     btn_new.Top = PointToClient(MousePosition).Y - panel4.Top;   
  21.     //加载事件   
  22.     btn_new.Click += new System.EventHandler(this.button1_Click);   
  23.     btn_new.MouseLeave += new System.EventHandler(this.button1_MouseLeave);   
  24.     btn_new.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown);   
  25.     btn_new.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);   
  26.     btn_new.Parent = panel4;   
  27.     name++;   
  28. }  

 

 

 

 

 

 

view plaincopy to clipboardprint?
  1. private void panel4_DragEnter(object sender, DragEventArgs e)   
  2. {   
  3.     e.Effect = DragDropEffects.Copy;   
  4. }   
  5.   
  6. private void button1_Click(object sender, EventArgs e)   
  7. {   
  8.     groupBox1.Text = (sender as Button).Name + "属性";   
  9.     textBox1.Text = (sender as Button).Text;   
  10.   
  11. }   
  12.   
  13. private void button4_MouseDown(object sender, MouseEventArgs e)   
  14. {   
  15.     //判断鼠标左键按下   
  16.     if (e.Button == MouseButtons.Left)   
  17.     {   
  18.         Button btn = (Button)(sender);   
  19.         //初始化拖放操作。   
  20.         btn.DoDragDrop(btn, DragDropEffects.Copy);   
  21.     }   
  22. }  
 

 

posted on 2009-08-10 16:02  superlee  阅读(248)  评论(0编辑  收藏  举报