如何将它从一个面板拖放按钮,另一个小组? [英] How to drag and drop a button from one panel to another panel?

查看:230
本文介绍了如何将它从一个面板拖放按钮,另一个小组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个形式5的面板,并在两个不同的面板的两个按钮,现在的要求是从一个面板的按钮移动到另一

I have 5 panels in a form and two buttons in two different panels, now the requirement is to move the buttons from one panel to another.

请建议我一个code。

Please suggest me a code.

推荐答案

有关演示,放置在窗体上的两个面板,在面板中的一个按钮:

For demonstration, place two panels on a form and a button in one of the panels:

public Form1() {
  InitializeComponent();

  panel1.AllowDrop = true;
  panel2.AllowDrop = true;

  panel1.DragEnter += panel_DragEnter;
  panel2.DragEnter += panel_DragEnter;

  panel1.DragDrop += panel_DragDrop;
  panel2.DragDrop += panel_DragDrop;

  button1.MouseDown += button1_MouseDown;
}

void button1_MouseDown(object sender, MouseEventArgs e) {
  button1.DoDragDrop(button1, DragDropEffects.Move);
}

void panel_DragEnter(object sender, DragEventArgs e) {
  e.Effect = DragDropEffects.Move;
}

void panel_DragDrop(object sender, DragEventArgs e) {
  ((Button)e.Data.GetData(typeof(Button))).Parent = (Panel)sender;
}

这篇关于如何将它从一个面板拖放按钮,另一个小组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆