Click here to Skip to main content
15,749,281 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have created three forms in C#. when i open second form I need to close previous form.
How to do this? Can anyone help me please.


1 solution

In the Form1 code:
Form2 f2 = new Form2();

The only problem with this is that if the current form is your main form (the one that opens in the Main method of Program.cs) that this will close the application. In that case, use Hide instead of Close, or Hide it first, then use ShowDialog instead of Show - try it and you will see what I mean!
Share this answer
sencsk 26-Sep-10 13:37pm    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900