Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Can help ;

I have 2 panel

First panel has buttons and i need to drag drop copy of the button from first panel to second panel. like dublicate

Thanks
Posted
Comments
Kenneth Haugland 7-Aug-13 2:30am    
WinFrom or WPF?
Qurbonov 7-Aug-13 3:44am    
Winform. Sorry :) I forget about this
Maciej Los 7-Aug-13 2:40am    
What have you done so far? Where are you stuck?
Qurbonov 7-Aug-13 3:46am    
I have
namespace DragnDrop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
panel1.AllowDrop = true;
panel2.AllowDrop = true;

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

//panel1.DragDrop += panel_DragDrop;
panel2.DragDrop += panel_DragDrop;
panel2.DragOver += panel2_DragOver;

button1.MouseDown += button1_MouseDown;
}

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

//void panel2_DragEnter(object sender, DragEventArgs e)
//{
// e.Effect = DragDropEffects.All;
//}

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

private void panel2_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
}
}

I try to get dublicate of button on DragOver
Maciej Los 7-Aug-13 3:59am    
On drop event you need to create new button, like this: Button btn = new Button; then set its properties based on properties of copied button. That's all ;)

1 solution

I would suggest you to start here:
Drag and Drop Overview[^]
Walkthrough: Performing a Drag-and-Drop Operation in Windows Forms[^]

I think it's enough for start.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900