简体   繁体   中英

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!

您可以尝试用全新的图片替换它:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM