juliet_zl

juliet_zl

  • NA
  • 37
  • 0

Show, hide, and show again

Jan 15 2004 10:53 PM
Forgive me if the question sounds stupid, I just start to play around with windows forms. If I create another form from the first form, say with a button click. Normally we will do: btnOpen_Click(object sender, EventArgs e) { Form2 form = new Form2(); form.Show(); } Say, if in Form2, I have a exit button, which would close the form: btnExit_Click(object sender, EventArgs e) { this.Hide(); } Now, my question is, if I (or the user) wish to open Form2 again, from the first form. Using the code above, another Form2 would be instantiate again because of the line: Form2 form = new Form2(); Then the old Form2 which had been instantiated earlier would be orphaned and waited for the garbage collector to dispose it. This sounds dirty to me as the application might use up a lot of reosurces. Is there a way to check whether Form2 had been instantiated earlier, and if yes, then just call: form2.Show(); instead of instantiating a new form? Thanks.

Answers (4)