Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear image on picturebox

How can I clear draw image on picturebox? The following doesn't help me:

pictbox.Image = null; pictbox.Invalidate(); 

Please help.

EDIT

private void pictbox_Paint(object sender, PaintEventArgs e)  {       Graphics g = e.Graphics;       vl.Draw(g, ref tran.realListForInsert);  }   public void Draw(Graphics g, ref List<double> arr)  {      g.DrawRectangle(new Pen(Brushes.Red, 3), nodeArr[Convert.ToInt32(templstName)].pict.Location.X, nodeArr[Convert.ToInt32(templstName)].pict.Location.Y, 25, 25);      g.DrawRectangle(new Pen(Brushes.Green, 3), nodeArr[Convert.ToInt32(templstArgName)].pict.Location.X, nodeArr[Convert.ToInt32(templstArgName)].pict.Location.Y, 25, 25);      nodeArr[Convert.ToInt32(templstName)].text.Text = arr[Convert.ToInt32(templstArgName)].ToString();      arr[Convert.ToInt32(templstName)] = arr[Convert.ToInt32(templstArgName)];  }  
like image 979
ktarik Avatar asked May 02 '11 10:05

ktarik


People also ask

How do you clear the image box in VB net?

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.


2 Answers

Setting the Image property to null will work just fine. It will clear whatever image is currently displayed in the picture box. Make sure that you've written the code exactly like this:

picBox.Image = null; 
like image 150
Cody Gray Avatar answered Sep 30 '22 09:09

Cody Gray


As others have said, setting the Image property to null should work.

If it doesn't, it might mean that you used the InitialImage property to display your image. If that's indeed the case, try setting that property to null instead:

pictBox.InitialImage = null; 
like image 30
Frédéric Hamidi Avatar answered Sep 30 '22 09:09

Frédéric Hamidi