tags:

views:

116

answers:

1

i created a drawing apllication in my solution by this code.by this i can draw images in a picturebox and can to save. when i click the clearbutton the image on the picturebox is cleared but the problem is after clearing the image i can't draw any thing in the picturebox without the form's reload

dim mousepath as new system.drawing.drawing2d.graphicspath()

in pageload 
picturebox1.image=new bitmap(picturebox1.clientsize.height,picturebox1.clientsize.width)

picturebox1_paint(...)
myusercolor=(sysytem.drawing.color.black)
myalpha=100
using g as graphics=graphics.fromimage(picturebox1.image)
g.clear(color.white)
dim currentpen as pen=new pen(color.fromargb(myalpha,myusercolor),mypenwidth) g.drawpath(currentpen,mousepath) 

in mousedown
if e.button=mousebutton.left then
mousepath.startfigure()
end if

in mousemove
if e.button=mousebutton.left then
mousepath.addline(e.x,e.y,e.x,e.y)
end if
picturebox1.invalidate

clearbutton_click
picturebox1.image.dispose()
picturebox1.image=nothing

PROBLEM: if anyone knows the solution for this problem please help me.it's very important for me.thank you

+1  A: 

when you clear, you set picturebox1.image=nothing, but then your Graphics object comes from that image. That's why it won't work. You have to set a new Bitmap when you clear like the first time :

picturebox1.image=new bitmap(picturebox1.clientsize.height,picturebox1.clientsize.width)
mousepath.Reset();
najmeddine
i already used this .at that time in the mouseover the last drawn picture will appear
in fact your drawing is stored in your mousepath, so you have to clear it also: mousepath.Reset().
najmeddine
where can i place this code?
in clearbutton_click
najmeddine
ohhh its working perfectly..thank you..thank you...