i want to move to form2 on buttonclick at form1 and at the same time i want to close form1
i want to go to form2 on buttonclick of form1 and close form1 at the same time
Collapse
X
-
Tags: None
-
The simplest way to accomplis this is to add this to a button event handler in form1:
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.Code:frmTest2 myForm = new frmTest2(); myForm.Show(); this.Close();
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:
Code:frmTest mainForm = new frmTest(); Application.Run(mainForm); //executes after mainForm has closed Form nextForm = mainForm.NextFormToShow; Application.Run(nextForm);
Comment