In my application, I am using two forms mainform and subForm. The mainForm has simple login application. On click of the button (btnClick) in mainForm(if the login credentials matches), it should get directed to the subForm. This I can do easily. but the problem is that the mainForm still visible and whenever I close the mainForm it is also closing the subForm. Which I dont want to happen. and If I give this.Close() after the function same problem is happening.
” How to close the mainForm after opening the subForm. “
I have tried the below code:
btnClick Event:
subForm newSubForm = new subForm();
newSubForm.Show();
newSubForm.RegisterMainForm(this);
this.Close();
RegisterMainForm is just a internal method to consider the actual subForm.
Once you close the main form, your application’s message loop terminates, which causes the entire application to exit. The Windows message loop is tied to your main form because that’s the one you started
Application.Run(new mainform()).
Try some other approach in your Program.cs