tmighty
tmighty

Reputation: 11399

VB.NET: Clearing a picturebox

None of the code that I have seen so far to clear a picturebox achieved what I needed. I wanted to clear a picturebox so that I can draw something new over a "blank" background.

Here is my code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    PictureBoxClear(Me.PictureBox1)

    m_i = m_i + 1
    Dim nPT As New Point(0, 0)
    Me.ImageList1.Draw(Me.PictureBox1.CreateGraphics, nPT, m_i)

End Sub
Public Sub PictureBoxClear(ByRef pb As PictureBox)

    pb.Image = Nothing

End Sub

Saying

 .Image = Nothing

seems to completely remove the image so that I can not really draw something over it afterwards. I just wanted to clear my picturebox so that it would then ready be get some drawing again.

Thank you!

Upvotes: 1

Views: 9780

Answers (1)

nneonneo
nneonneo

Reputation: 179422

You can try replacing it with a brand new image:

pb.Image =  New Bitmap(pb.ClientSize.Width, pb.ClientSize.Height)

Upvotes: 1

Related Questions