0

I have these codes in my program. But the this.close doesn't function. And because the previous form didn't close, it overlaps with the second one. What should I do to be able to open just one form at a time? I have set a value to get the content of lblScore located in form1 to be displayed on form2. But, I wish to close the form1 so that the only form that is open will be the form2. How can I do that?

if (score >= 2) {
    timerDrop.Enabled = false;
    MessageBox.Show("Time's Up! You can now proceed to the next Level!");
    frmLevel2 lvl2 = new frmLevel2();
    lvl2.Show();
    lvl2.set = lblScore.Text;
    this.Close();
} else {
    timerDrop.Enabled = false;
    MessageBox.Show("Time's Up! GAME OVER!");
    frmMenu frmBackToMenu = new frmMenu();
    frmBackToMenu.Show();
    this.Close();
}

Thanks.

Sylca
  • 2,523
  • 4
  • 31
  • 51

1 Answers1

0

What about hiding the first form, then when closing the 2nd the application can stop? like this:

(used a button on form1 to open form2, then hide form1, then if form2 is closed form1 closes also);

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form2 form2 = new Form2();
            form2.ShowDialog();
            this.Close();

        }
Random IT Guy
  • 625
  • 1
  • 8
  • 16