Closing a Form

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();
 
R

Ralf

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top