Clear drawn lines

mistik1
10-02-2006, 11:23 PM
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(color.black,1)
g2.drawline(.....)
picturebox1.invalidate(false) 'not sure what this does

And in the paint event for picturebox1 I have
e.Graphics.drawimage(picImg,0,0)

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.

Iceplug
10-03-2006, 04: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