Reputation: 533
'i using this code in the piicturebox1_paint
myusercolor=(sysytem.drawing.color.black)
myalpha=100
using g as graphics=graphics.fromimage(picturebox1.image)
g.clear(color.white)
dim currentpen as object=new pen(color.fromargb(myalpha,myusercolor),mypenwidth)
g.drawpath(ctype(currentpen,pen),mousepath)
end using
'using in the form_load '
picturebox1.image=new bitmap(.....)
'in the clearbutton_click '
picturebox1.image=nothing
by this code i have a problem that when i click the clear button the picturebox is cleared.but in the picturebox's mouseover the last drawn picture will appear.so i cant draw a new image ..
Upvotes: 0
Views: 597
Reputation: 12538
You're drawing in the Picturebox1_paint event? This will fire every time the control is affected by such things as moving the form or in this case a mouse moving over it. You should be drawing outside that event, but where depends on what you're trying to do.
Upvotes: 1
Reputation: 158389
It's a guess, but I think that mousepath
contains the "drawing" that the user has made. When initializing a new image (probably in the clearbutton_click
event handler) you will also need to clear that data:
If Not mousepath Is Nothing Then
mousepath.Dispose()
End If
mousepath = new GraphicsPath()
As a side note, not directly related to your question, I would suggest two improvements in how the Pen
is handled. Look at the following two code lines (from your sample above):
dim currentpen as object=new pen(color.fromargb(myalpha,myusercolor),mypenwidth)
g.drawpath(ctype(currentpen,pen),mousepath)
This first creates a new Pen
and stores it in the object
variable currentpen
. Since currentpen
is declared as object
, you need to cast it to Pen
when passing it to DrawPath
. If you instead declare currentpen
as a Pen
you don't need to do that cast. Also, Pen
implements IDisposable
so you should either call Dispose
on it, or wrap it into a using
block:
Using currentpen as Pen = new Pen(Color.FromArgb(myalpha,myusercolor),mypenwidth)
g.drawpath(currentpen,mousepath)
End Using
Upvotes: 0