I have to forms in my project one form to connect and the main form I want when the user and the password are true to close the current login form and open the main form, I created the code which check if the user name and the password are true, and I used an IF statement if the check is true, but the problem is when I press the connect button the two forms are disappeared this is the code I tried to use :
if (allowCnx)
{
Form1 mainForm = new Form1();
mainForm.Show();
this.Close();
}
The likely problem here is that you likely have your login form set as the main form (or the form that is run on startup). When that form is closed the entire application closes.
There are a number of solutions, but one that I would suggest is to ensure that
Form1is set as the actual startup form, and then in it’s form load method have something like this: