c# - How can I make images drag and drop-able to reorder them? -
i'm building application in i'd user able reorder pictures in form in 2 columns. i've got flowlayoutpanel of set width, , pictures added via openfiledialog , scaled half width (minus allowance scroll bar) of flow layout panel.
this i'm stuck - i've tried adding images labels, buttons, , pictureboxes , can't work out how move them around. gave on labels because canselect
false - although didn't know if have made difference - , moved on buttons because realised picture boxes existed. i'm open switching out controls use images need in 2 columns.
here's code have dragenter , dragdrop events:
private void flowlayoutpanel_6_cards_dragenter(object sender, drageventargs e) { e.effect = dragdropeffects.all; } private void flowlayoutpanel_6_cards_dragdrop(object sender, drageventargs e) { messagebox.show("dropped"); }
how can implement this? controls should use , properties should looking @ make possible?
so @taw's comment know have add dodragdrop call mousedown event on whatever you're dragging. now-working code below (thanks this tutorial):
private void flowlayoutpanel_6_cards_dragdrop(object sender, drageventargs e) { picturebox picture = (picturebox)e.data.getdata(typeof(picturebox)); flowlayoutpanel _source = (flowlayoutpanel)picture.parent; flowlayoutpanel _destination = (flowlayoutpanel)sender; if (_source != _destination) { //where did from? } else { point p = _destination.pointtoclient(new point(e.x, e.y)); var item = _destination.getchildatpoint(p); int index = _destination.controls.getchildindex(item, false); _destination.controls.setchildindex(picture, index); _destination.invalidate(); } } private void flowlayoutpanel_6_cards_dragenter(object sender, drageventargs e) { e.effect = dragdropeffects.all; } void p_mousedown(object sender, mouseeventargs e) { picturebox p = (picturebox)sender; p.dodragdrop(p, dragdropeffects.all); }
Comments
Post a Comment