tags:

views:

721

answers:

3

i have a form with a picturebox that will allow to draw a free hand picture.

i added the initialization of the image in the form_load and the click event of the clear button.but when i click the clear button the image will cleared and at the mouse move on the picturebox the last drawned image will shawn .if you can please help me

how can i validate the picturebox is empty. means i doesn't want to permit to save a empty image.

thank you...

+1  A: 
PictureBox1.Image = Nothing
adatapost
i already used this code .but there have an issue that when i click the clearbutton the image will cleared.but the mouse over on the picturebox the last drawn image will appear.
Can I see the code of MouseHover event? You may also add/remove event handler programatically. **RemoveHandler PictureBox1.MouseHover, AddressOf PictureBox1_MouseHover**
adatapost
'i using this code in the piicturebox1_paintmyusercolor=(sysytem.drawing.color.black)myalpha=100using 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_loadpicturebox1.image=new bitmap(.....)'in the clearbutton_clickpicturebox1.image=nothing
A: 
bool clearImage;
clearButton_Click(...)
{
  clearImage = true;
  img.Invalidate();
}

img_Paint(...)
{
  if (clearImage)
  {
    clearImage = false;
    e.Graphics.Clear(Color.White);
  }
}

VB.NET

Private clearImage As Boolean 
Private Sub button_click(ByVal sender As Object, ByVal e As eventargs) Handels....
    clearImage = True
    img.Invalidate()
End Sub
Private Sub img_Paint(ByVal sender As Object, ByVal e As ...) Handels ....
    If clearImage Then
        clearImage = False
        e.Graphics.Clear(Color.White)
    End If
End Sub
Petoj
how can i use this code
declare a bool clearImage in the form. then double click the button so that you get the _Click event and add the code i wrote in the event. click on the image and find the paint event and add the code in the paint event?
Petoj
img is your picturebox and clearButton is your button.
Petoj
is this vb code?
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
no this is c# code wait 2 seconds and ill edit it and add vb.net code
Petoj
than you.but i used this code.but no chage.the image tha i drawn last will display on the mouseover.
Then you have some thing else that is doing this it should be cleared!
Petoj
A: 

There might be some logic error in your code. Check the mousemove or mousehover event and make sure it is not assigning an image to the picturebox.

Instead of assigning nothing to the new image with the button, you could clear the the existing image. This might be better because you won't have to create a new image before you can draw on it again.

g = Graphics.FromImage(PictureBox1.Image)
g.Clear(PictureBox1.BackColor)
xpda
'i using this code in the piicturebox1_paintmyusercolor=(sysytem.drawing.color.black)myalpha=100using 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_loadpicturebox1.image=new bitmap(.....)'in the clearbutton_clickpicturebox1.image=nothing