Clear image on picturebox

后端 未结 13 1772
不思量自难忘°
不思量自难忘° 2020-12-05 13:13

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

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

Please help.

相关标签:
13条回答
  • 2020-12-05 13:26

    I've had a stubborn image too, that wouldn't go away by setting the Image and InitialImage to null. To remove the image from the pictureBox for good, I had to use the code below, by calling Application.DoEvents() repeatedly:

                Application.DoEvents();
                if (_pictureBox.Image != null)
                    _pictureBox.Image.Dispose();
                _pictureBox.Image = null;
                Application.DoEvents();
                if (_pictureBox.InitialImage != null)
                    _pictureBox.InitialImage.Dispose();
                _pictureBox.InitialImage = null;
                _pictureBox.Update();
                Application.DoEvents();
                _pictureBox.Refresh();
    
    0 讨论(0)
  • 2020-12-05 13:27
    private void ClearBtn_Click(object sender, EventArgs e)
    {
        Studentpicture.Image = null;
    }
    
    0 讨论(0)
  • 2020-12-05 13:27

    You need the following:

    pictbox.Image = null;
    pictbox.update();
    
    0 讨论(0)
  • 2020-12-05 13:32

    Its so simple! You can go with your button click event, I used it with a button property Name: "btnClearImage"

    // Note 1a:
    // after clearing the picture box 
    // you can also disable clear button 
    // by inserting follwoing one line of code:
    
    btnClearImage.Enabled = false   
    
    // Note 1b:
    // you should set your button Enabled property
    // to "False"
    // after that you will need to Insert 
    // the following line to concerned event or button
    // that load your image into picturebox1 
    // code line is as follows:
    
    btnClearImage.Enabled = true;
    
    0 讨论(0)
  • 2020-12-05 13:33
    if (pictureBox1.Image != null)
    {
        pictureBox1.Image.Dispose();
        pictureBox1.Image = null;
    }
    
    0 讨论(0)
  • 2020-12-05 13:44

    I used this method to clear the image from picturebox. It may help some one

    private void btnClear1_Click(object sender, EventArgs e)
            {
    
                img1.ImageLocation = null;
            }
    
    0 讨论(0)
提交回复
热议问题