c# - Drog and Drop TableLayoutPanel in a panel? -
i'm trying drag , drop tablelayoutpanel in panel using winforms/c#, drag of tablelayout works problem tablelayoutpanel droped doesn't appear !! solution please ??
private void registration_load(object sender, eventargs e) { panel2.allowdrop = true; tablelayoutpanel1.allowdrop = true; panel2.dragenter += panel2_dragenter; panel2.dragdrop += panel2_dragdrop; tablelayoutpanel1.mousedown += tablelayoutpanel1_mousedown; } private void panel2_dragenter(object sender, drageventargs e) { e.effect = dragdropeffects.move; } private void panel2_dragdrop(object sender, drageventargs e) { ((tablelayoutpanel)e.data.getdata(typeof(tablelayoutpanel))).parent (panel)sender; } private void tablelayoutpanel1_mousedown(object sender, mouseeventargs e) { tablelayoutpanel1.dodragdrop(tablelayoutpanel1, dragdropeffects.move); }
the code inadequate, you'll need @ least set location property of dropped tlp ensure within panel bounds and/or located @ mouse cursor. , z-order matters, setting parent property puts @ bottom can overlapped other controls in panel, need bringtofront().
try this:
private void panel2_dragenter(object sender, drageventargs e) { if (e.data.getdatapresent(typeof(tablelayoutpanel))) e.effect = dragdropeffects.move; } private void panel2_dragdrop(object sender, drageventargs e) { var tlp = (tablelayoutpanel)e.data.getdata(typeof(tablelayoutpanel)); tlp.location = panel2.pointtoclient(new point(e.x, e.y)); tlp.parent = panel2; tlp.bringtofront(); }
Comments
Post a Comment