VB.NET:清除图片框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13006549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:00:37  来源:igfitidea点击:

VB.NET: Clearing a picturebox

vb.netpicturebox

提问by tmighty

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!

谢谢!

采纳答案by nneonneo

You can try replacing it with a brand new image:

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

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