【发布时间】:2009-10-14 13:46:21
【问题描述】:
我希望在将某个控件拖放到另一个表单时获得另一个副本。我的代码导致移动整个控件。鉴于我希望它们具有相同的引用,因为源每秒都会更新值,因此有没有办法让它们中的两个同时显示。
这是我的代码
public partial class DragDropForm : Form
{
public DragDropForm()
{
InitializeComponent();
}
private void tableLayoutPanel1_DragEnter(object sender, DragEventArgs e)
{
object data = e.Data.GetData(e.Data.GetFormats()[0]);
if (data is GaugeContainer)
{
GaugeContainer gauge = data as GaugeContainer;
tableLayoutPanel1.Controls.Add(gauge);
}
else if (data is DataGridView)
{
DataGridView table = data as DataGridView;
tableLayoutPanel1.Controls.Add(table);
}
}
private void tableLayoutPanel1_DragDrop(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy ;
}
}
// IN THE SOURCE FORM !!!!
private void topCompaniesGridView_MouseDown(object sender, MouseEventArgs e)
{
this.DoDragDrop(this.topCompaniesGridView, DragDropEffects.Copy);
}
【问题讨论】:
标签: c# .net winforms drag-and-drop