c# - FillRectangle on button Click into the form -
i want draw(fill) rectangle in form when click on button. can't manage create work , dont know wrong.
private void form1_paint(object sender, painteventargs e) { graphics g = e.graphics; //verklaart naar object graphics vierkant vierkant = new vierkant(); } private void vierkant_click(object sender, eventargs e) { solidbrush mybrush = new solidbrush(color.cyan); g.fillrectangle(mybrush, 20, 20, 50, 50); }
shall drawing persist or not? meaning: shall still there after eg resize or maximize etc? also: vierkant?
to create persist can utilize code this:
private void form1_paint(object sender, painteventargs e) { if (paintit) using( solidbrush mybrush = new solidbrush(color.cyan) ) e.graphics.fillrectangle(mybrush, 20, 20, 50, 50); } bool paintit = false; private void vierkant_click(object sender, eventargs e) { paintit = true; this.invalidate(); // ?? supposed or be?? // vierkant vierkant = new vierkant(); }
this work if both events hooked up. more interesting drawings need store more bool flag lists of drawaction class need invent include shapes, data, brushes etc..
if replace paintit = true;
paintit = !paintit;
rectangle appear , disappear on each click..
c# onclick fill
No comments:
Post a Comment