Click here to Skip to main content
15,562,015 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
private void btnClose_Click(object sender, EventArgs e)
{ 
    Form frmSecond = new frmSecond(); 
    frmSecond.Show();  
    frmSecond.Activate();  
    this.Close();
}


This code closes the first form then it enters into Program.cs and then it opens the same form again and not frmSecond. I want to close the first form and then open the second form. Please help.

Thanks!!
Posted
Updated 22-May-10 4:20am
v2

You can modify the code in Program.cs to open a second form after the first one closes:
C#
static void Main()
{
	Application.EnableVisualStyles();
	Application.SetCompatibleTextRenderingDefault(false);
	Application.Run(new Form1());
	Application.Run(new Form2());
}
 
Share this answer
 
If the first form is the startup form, you cannot close it - you can only hide it[^].
 
Share this answer
 
v3
 
Share this answer
 
v2

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