Clear drawn lines

10-03-2006, 12:23 AM
I have a project that deals with drawing lines. Currently when I push the draw button the new lines are just drawn over the old lines. I would like to erase the old lines so nothing shows but the new lines. I am having a really tough time figuring out how to do this.

In the form_load event I create a bitmap called picImg that I get like this
g1 = Graphics.fromhwnd(picturebox1.handle)
picImg = new bitmap(picturebox1.clientrectangle.width, picturebox1.clientrectangle.height,g1)

With the button I draw a couple lines. Something like this
g2 = graphics.fromimage(picImg)
p1 = new pen(,1)
picturebox1.invalidate(false) 'not sure what this does

And in the paint event for picturebox1 I have

I like how the lines stay drawn after a minimize so I want to keep that functionality. But I also want to erase the current lines when I click the button so I can draw the new lines without seeing the old as well.

10-03-2006, 05:47 PM
First rule (well probably third): Do not create a new graphics object everytime you need to draw something - always try to recycle an old one.

That being said, if you do recycle the graphics objects are you are supposed to, then you can simply clear the graphics object to draw more lines on a new slate.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum