winforms - C# Order a list of labels by location on screen -
how can order list of labels location on screen? labels move around screen in x axis, code have notice isn't working.
labels.orderby(x => x.location.x);
thank in advance!
edit: how i'm testing if works or not...
private void actualizarposicoes() { labels.orderby(x => x.location.x); messagebox.show(labels.first.value.text.tostring()); }
but want use when label removed screen first have make orderby working.
private void reorder(label lb) { labels.orderby(x => x.location.x); var = labels.getenumerator(); var node = it.current; while (it.movenext()) { var nextnode = it.movenext(); if (nextnode != null) { if (nextnode.equals(lb)) { nextnode = it.movenext(); it.current.location = new point(node.right, 0); } } node = it.current; } }
i have global linkedlist called labels:
private linkedlist<label> labels;
i suggest use flowlayoutpanel container labels. removing label automatically re-arrange other labels.
here sample - assume have labelsflowlayoutpanel
host labels , addlabelbutton
add labels:
private void addlabelbutton_click(object sender, eventargs e) { label label = new label(); label.text = datetime.now.tolongtimestring(); label.doubleclick += label_doubleclick; labelsflowlayoutpanel.controls.add(label); } void label_doubleclick(object sender, eventargs e) { label label = (label)sender; labelsflowlayoutpanel.controls.remove(label); label.doubleclick -= label_doubleclick; }
each time click addlabelbutton
new label created , inserted right of other labels. double-clicking on label remove , re-arrange other labels.
further info - windows forms controls lesson 5: how use flowlayout panel
Comments
Post a Comment