While we have similar functionality seemingly working correctly elsewhere, we have an issue with one page and I don’t see an obvious solution.
When trying to drag a button from one FlowLayoutPanel to another FlowLayoutPanel, it seemingly does not let it drag off the original FlowLayoutPanel.
The properties in the designer for the FlowLayoutPanel look to be correct at first glance, and when the button is instantiated, AllowDrag, AllowDrop, and Movable are all set to true.
Do you have any ideas what the issue may be?
Thanks!
Greg
Some things to consider:
1.The target panel must have AllowDrop = true
this.targetPanel.AllowDrop = true;
2. Even if AllowDrop is enabled, the target must process the drop:
private void TargetPanel_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Button)))
e.Effect = DragDropEffects.Move;
}
private void TargetPanel_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Button)))
{
var btn = (Button)e.Data.GetData(typeof(Button));
this.targetPanel.Controls.Add(btn);
}
}
3. Movable = true is not needed
Movable = true is for moving controls within the same container.
For dragging across containers, you must use DoDragDrop() and handle drop events.
I’ve attached a working sample where you can drag a button from one panel to another, hope this helps!
Please login first to submit.