-1

I made a form with a textbox for a user to enter a password and if the password is "hello", it'll reveal the pictureBox. I have the pictureBox visibility set to false. I have no clue how to do this, and have looked just about everywhere with no luck (yes, I'm a beginner).

public partial class Form2 : Form
{
    string secretPassword = "hello";
    public event EventHandler VisibleChanged;

    public Form2()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == secretPassword)
        {
            pictureBox1.VisibleChanged+= new EventHandler(this.PictureBox1_VisibleChanged) ;
        }
    }
stuartd
  • 70,509
  • 14
  • 132
  • 163

1 Answers1

0

It appears you're setting up an event handler rather than modifying the property.

The pictureBox1.VisibleChanged+= new EventHandler(this.PictureBox1_VisibleChanged) ; line is only adding a new event handler (this doesn't help much).

It should read:

pictureBox1.Visible = true;
pictureBox1.Refresh();

Calling the Refresh() method will force the picture box to update and show on the button click.

This question goes into detail about threads and how they relate to UI component visibility.

Community
  • 1
  • 1
Adam Wells
  • 545
  • 1
  • 5
  • 15