c# - How to create a panel with support for Drag and Drop? -
suppose have listbox custom elements , blank panel . when drag these items panel , must build on logic. example, if there's nothing panel , element located in middle. if there , new element stay near element closest . such possible implement?
for example:
i modified this answer of working drag , drop implementation adding sorting logic. placing item in middle visually can done css styling.
assumption: "closest it" means closest alphabetically.
public object lb_item = null; private void listbox1_dragleave(object sender, eventargs e) { listbox lb = sender listbox; lb_item = lb.selecteditem; lb.items.remove(lb.selecteditem); } private void listbox1_dragenter(object sender, drageventargs e) { if (lb_item != null) { listbox1.items.add(lb_item); lb_item = null; // here added logic: // sort items added // (thereby placing item in middle). listbox1.sorted = true; } } private void listbox1_mousedown(object sender, mouseeventargs e) { lb_item = null; if (listbox1.items.count == 0) { return; } int index = listbox1.indexfrompoint(e.x, e.y); string s = listbox1.items[index].tostring(); dragdropeffects dde1 = dodragdrop(s, dragdropeffects.all); } private void form1_dragdrop(object sender, drageventargs e) { lb_item = null; }
Comments
Post a Comment