Hi, i just want to ask a quick question.
I wish to draw a shape in C# using the GDI+ and .net framework 3.5 in visual studio 2008, next i would like to delete the shape i have drawn when i press a button, however i do not wish to remove everything which is on the screen as i have some static GDI+ shapes in which i wish to keep on the screen.
So say that i draw a circle at a point on the screen where the mouse is clicked, how can i remove this when i click on a button? Also say i draw three circles when i click the mouse at three given points on the screen, how can i remove all of these when i click on a button?
I can draw the shapes via mouse click and probably store the co-ordinates in an arraylist or something myself but what i do not know how to do is remove these shapes when they are no longer needed.
Thanks
Loading
Danatas GerviPosted Aug 4, 2009, 8:41 AM
The is the real reason to optimise the Paint event handler. This handler may be called many times in second - for example, when user will drag other window over the form.
Graphics object alredy exist in
PaintEventArgs- so, we should use it.
MarkPosted Aug 4, 2009, 8:57 AM
Ok so i have modified that code and did the rectangle code in which you supplied in the last bit of code. The rectangle still remains and the circles can either be removed all at once or one at a time by using count -1 etc.
Thanks for all of the help man, very much apprechiated. I still cannot believe i missed that .clear() and used a loop instead, having me in stitches laughing so much about it.
Thanks for the help, problem now solved
MarkPosted Aug 4, 2009, 7:35 AM
Basically everytime i was trying to draw a rectangle with your code it kept on removing that too with the circles, i think it was because i was using the same graphics object for it, so i created a seperate graphics object and use that. Now the rectangle remains and the circles disappear when i click on the button. This is the effect i wanted as i wanted other graphics objects to remain and just have the circles removed.
Here is my new code:
Many thanks for the help, if you think i've "over coded" something then you may modify it again. Other than that it is a thumbs up.
Nice one
Danatas GerviPosted Aug 4, 2009, 2:24 AM
I added on Form1 - only one button - "Delete".
MarkPosted Aug 3, 2009, 12:51 PM
Thanks
Danatas GerviPosted Aug 3, 2009, 12:35 PM
This is not so easy, as we want. :-)
Even if you want to keep the graphic on form after resizing – you should redraw it on form Paint event. To do so, your form should keep collection of graphics objects("Coordinates Keeper" ) – with all necessary data to repaint it.
If you will create such collection, you can easy erase the graphics from screen by removing the instance of "Coordinates Keeper" from collection, and calling Refresh of form.