graced

can i perform a drag and drop operation in a FlowLayoutPanel

Re: Windows Forms General drag and drop in FlowLayoutPanel

nobugz

Yes, it implements the normal D+D events.





Re: Windows Forms General drag and drop in FlowLayoutPanel

graced

i have tried to drag and drop a label in another label's position so that they can change their positions (implementing the TopDown direction). but it does not work.

static void newPanel_DragDrop(object sender, DragEventArgs e)
{
MainGUI.currentControl.Location = MainGUI.panel1.PointToClient(new Point(e.X,e.Y));

}

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






Re: Windows Forms General drag and drop in FlowLayoutPanel

nobugz

Changing the Location property won't work, it is being controlled by the FlowLayoutPanel. That is its job. You'll need to rearrange the order of the controls in the FlowLayoutPanel's Controls property. That's awfully tricky, all you got is SendToBack() and BringToFront()...





Re: Windows Forms General drag and drop in FlowLayoutPanel

danielgary

Actually, this isn't correct.

Inside FlowLayoutPanel.Controls is a little used function called SetChildIndex(Control c, int index) which allows you to set an object to a specific index.

Since FlowLayoutPanel uses control's indices to determine which order to draw them in, you can set this to whichever control's index you are wanting to swap with, and it will bump that controls index up by one, and every one after that.