i have two window application forms form1-registeruser.cs form2-details.cs on clicking REGISTER button on form1,form2 is opened but form1 is still there .....i am not getting how to close form1 with form2 still open my code was as follows private void REGISTERbtn_Click(object sender, EventArgs e) { details obj=new details(); obj.show(); close(); } but this code closes both the forms ,form2 appear just for a second
If registerUser form is the form called from Program.cs, then it'll exit the application as soon as it closes. Instead, just hide it. private void REGISTERbtn_Click(object sender, EventArgs e) { details obj=new details(); obj.show(); this.Hide(); }
but this does not close the form ,it hides it....and then again when i run the application....it shows the error coz the application is still not completely closed....the form was only hidden not closed...although we cn continue neglecting that error
try this private void REGISTERbtn_Click(object sender, EventArgs e) { details obj=new details(); obj.show(); this.Dispose(); }
the dispose method will do the same thing as the Close method. If you wanted to close the Application when there is a hidden form open, just set up a Form Closing Event that calls this Method: Application.Exit()