我想將某個控件的另一個副本拖放到另一個窗體時。我的代碼導致移動整個控件。是否有辦法一次顯示它們中的兩個,因爲我希望它們具有相同的引用,因爲源每秒更新一次值。將控件從一個窗體拖放到另一個窗體導致移動控件
這裏是我的代碼
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);
}