拖动时我想复制面板,而不是移动面板

时间:2013-11-12 09:02:27

标签: c# winforms oledragdrop

我想将面板从一个tableLayoutPanel拖到另一个tableLayoutPanel。我也想要复制面板,而不是移动;也就是说,我希望将它们复制(从tableLayoutPanel1到tableLayoutPanel2),将项目保留在tableLayoutPanel1中。 我可以这样做吗?如果你能给我一个想法,它会很棒。谢谢

    public Form1()
    {
        InitializeComponent();
        panel1.AllowDrop = true;
        panel2.AllowDrop = true;
        panel3.AllowDrop = true;

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

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

    private void panel3_MouseDown(object sender, MouseEventArgs e)
    {
        DoDragDrop(panel3, DragDropEffects.Copy);
    }
    private void panel3_MouseMove(object sender, MouseEventArgs e)
    {
        DoDragDrop(panel3, DragDropEffects.Copy);
    }
    private void panel_DragEnter(object sender, DragEventArgs e)
    {

        e.Effect = DragDropEffects.Copy;
    }
    private void panel_DragDrop(object sender, DragEventArgs e)
    {
        ((Panel)e. Data . GetData(typeof(Panel))).Parent = (Panel)sender;
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
}

}

1 个答案:

答案 0 :(得分:0)

您需要在MouseDown处理程序中创建一个新面板,将其属性设置为原始属性,将其添加到表单并使用DoDragDrop与此新面板。