Umair Yaseen Umair Yaseen - 3 months ago 29
C# Question

PictureBox Show and Dispose

I want to show a

PictureBox
on button click, this should be on first click Show
PictureBox
, and on next click Hide
PictureBox
, again on third click show
PictureBox
and similar on fourth click again hide the
PictureBox
.

I have tried below code but it stuck after dispose of picture.

public bool i;
private void button1_Click(object sender, EventArgs e)
{
if (!i)
{
m1();
i = true;
}
else
{
m2();
i = false;
}
}

public void m1()
{
pictureBox1.Show();
}

public void m2()
{
pictureBox1.Dispose();
}

Answer
// Show the picture box
pictureBox.Visible = true;

// Hide the picture box 
pictureBox.Visible = false;