Question

I have a CustomControl containing a button with a label underneath. How can I drag and drop this custom control no matter from where I start dragging and where I drop it on another custom control (to rearange them). To make the sender and the receiver to be the whole custom control, because if I drag from the button the sender is the button and i'm dragging only the button not the whole custom control.. I want to drag one over another to add it at that position.

Was it helpful?

Solution

Found a solution:

private void flowLayoutPanel1_DragDrop(object sender, DragEventArgs e)
{
    Control target = new Control();

    target.Parent = sender as Control;

        if (target != null)
        {
            int targetIndex = FindCSTIndex(target.Parent);
            if (targetIndex != -1)
            {
                string cst_ctrl = typeof(CustomControl).FullName;
                if (e.Data.GetDataPresent(cst_ctrl))

                {
                    Button source = new Button();
                    source.Parent = e.Data.GetData(cst_ctrl) as CustomControl;

                    if (targetIndex != -1)
                        this.flowLayoutPanel1.Controls.SetChildIndex(source.Parent, targetIndex);
                }
            }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top