The simplest way to accomplis this is to add this to a button event handler in form1:
-
frmTest2 myForm = new frmTest2();
-
myForm.Show();
-
this.Close();
-
but this only works if form1 is not the main application form. If form1 is the main application form then this merely kills the application.
To do this with all forms and have it work with the main application form you would have to add a property to your forms, say NextFormToShow, that returns a form object. Then whatever code is checking for form1 to be closed would have to show the next form.
In Program.cs, that would mean having something like the following lines:
- frmTest mainForm = new frmTest();
-
Application.Run(mainForm);
-
-
//executes after mainForm has closed
-
Form nextForm = mainForm.NextFormToShow;
-
Application.Run(nextForm);