Closing a Form

  • Thread starter Thread starter Eric W
  • Start date Start date
E

Eric W

I have two forms.

Form1 and Form2

I want to be able to click a button on Form1 that will allow me to open
Form2 and then close Form1. Is this possible ?

My code isn't working, can anyone tell me what I'm doing wrong ?

Form f = new Form2();

f.Show();

this.Close();
 
Eric said:
I have two forms.

Form1 and Form2

I want to be able to click a button on Form1 that will allow me to open
Form2 and then close Form1. Is this possible ?

My code isn't working, can anyone tell me what I'm doing wrong ?

Form f = new Form2();

f.Show();

this.Close();

I am assuming that your application entry point (Main method) is located
in the code-behind for Form1.

Closing Form1 will actually close the application and any objects that
it created (including Form2).

I would suggest hiding the Form1:

Form2 f = new Form2();
f.Show();
this.Visible = false;

Hope that helps.
 
Back
Top