Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
清除Picturebox.backgroundimage中的c#_C#_Background Image_Picturebox - Fatal编程技术网

清除Picturebox.backgroundimage中的c#

清除Picturebox.backgroundimage中的c#,c#,background-image,picturebox,C#,Background Image,Picturebox,我有一个picturebox,可以将图像加载到它的.backgroundimage函数中,现在我有了一个按钮,可以清除图像,但不能。我已尝试使用此代码: secondcapturebox.Dispose(); 但这张照片仍在图片盒中。 请帮忙 谢谢你试过了吗 secondcapturebox.BackgroundImage = null; 你试过 secondcapturebox.BackgroundImage = null; 您必须将其设置为null。像这样: private vo

我有一个picturebox,可以将图像加载到它的.backgroundimage函数中,现在我有了一个按钮,可以清除图像,但不能。我已尝试使用此代码: secondcapturebox.Dispose(); 但这张照片仍在图片盒中。 请帮忙

谢谢你试过了吗

secondcapturebox.BackgroundImage = null;
你试过

secondcapturebox.BackgroundImage = null;

您必须将其设置为null。像这样:

    private void button1_Click(object sender, EventArgs e) {
        if (pictureBox1.BackgroundImage != null) {
            pictureBox1.BackgroundImage.Dispose();
            pictureBox1.BackgroundImage = null;
        }
    }

您必须将其设置为null。像这样:

    private void button1_Click(object sender, EventArgs e) {
        if (pictureBox1.BackgroundImage != null) {
            pictureBox1.BackgroundImage.Dispose();
            pictureBox1.BackgroundImage = null;
        }
    }

你选错了答案。不要因为尝试Dispose()时它不起作用而忽略它。您选择了错误的答案。不要因为尝试Dispose()时它不起作用而绕过它。欢迎使用StackOverflow!您的答案可能会受益于一点解释,为什么以及如何解决这个问题的代码。欢迎使用StackOverflow!您的答案可能会从一个小的解释中受益,这个代码为什么以及如何解决这个问题。