Dragging Button from one FlowLayoutPanel to another

0
0

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

  • You must to post comments
0
0

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!

Attachment
  • Xenitel Developers
    The picture I attached to the original post is to show that the button does not even seem to be able to leave the current panel. Hopefully that clarifies things.
  • Julie(ITG)
    I’ve provided a working sample. In order to assist you further I would need a compliable test case that shows the issue.
  • Xenitel Developers
    without looking I’m guessing drag targets not defined property ( Charles )
  • Xenitel Developers
    Again, the button isn’t even able to be dragged off the panel, so it is not able to be dragged to the other panel. I can try to provide further details later.
  • Gabriele Del Giovine
    Follow the instructions on sample project.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.