i new wpf. adding rectangle 1 after other on canvas on button click. when set height of specific rectangle textbox. overlaps on child rectangle.
eg:. when there 3 rectangles height=100
,width=200
& when set height of second rectangle 150
. child rectangle
must appear after second rectangle & must not overlap on third rectangle. possible?
static int val=0; list<uielement> itemstoremove = new list<uielement>(); private void btnadd_click(object sender, routedeventargs e) { int heigt = 0; int wegt = 0; if (!string.isnullorempty(txtheight.text) && !string.isnullorempty(txtwidth.text)) { heigt = int.parse(txtheight.text); wegt = int.parse(txtwidth.text); } rect = new rectangle(); rect.stroke = brushes.red; rect.strokethickness = 2; rect.height = heigt; rect.width = wegt; canvas.setleft(rect, 10); canvas.settop(rect, (rect.height) * val); rect.tag = val; canvasboard.children.add(rect); val = val + 1; //canvasboard canvas object foreach (uielement ui in canvasboard.children) { if (ui.gettype() == typeof(rectangle)) { itemstoremove.add(ui); } } }
for modifying height & width:
private void btnmodify_click(object sender, routedeventargs e) { int heigt = 0; int wegt = 0; if (!string.isnullorempty(txtheight.text) && !string.isnullorempty(txtwidth.text)) { heigt = int.parse(txtheight.text); wegt = int.parse(txtwidth.text); } rectangle recttoremove; foreach (uielement ui in itemstoremove) { if (ui.gettype() == typeof(rectangle) && ((rectangle)ui).tag.tostring() == txtmodifyrect.text) { recttoremove = ui rectangle; //itemstoremove.remove(recttoremove); recttoremove.height = heigt; recttoremove.width = wegt; //canvasboard.children.remove(recttoremove); break; } } }
this works fine. just want prevent overlapping of rectangle
on 1 , must appear 1 after other auto adjusting.
help appreciated!
in order effect want must change canvas wrappanel. way when add children canvas don't add location, arranges objects on own. want
<scrollviewer verticalscrollbarvisibility="auto" > <wrappanel name="objlist" > </wrappanel> </scrollviewer>
the scrollviewer let scroll if have more objects window can contain.
Comments
Post a Comment