I have a log in form on my app. Once a correct user name and pass word are provided I want the log in form to close and my main form to open. I had trouble doing this so I used a quick fix and coded it so that a succesful login meant the log in form’s Visible property got set to false (making it look like it had closed to the user). But I’m not happy with this solution since it means the log in form is always open.
The code I have on my frmLogIn is
Form fM = new frmMain();
this.Visible = false;
fM.Show();
How do I change this so that frmLogIn actually closes as frmMain opens?
PS. I also tried this code from another thread on these forums, but this doesnt work either.
Form fM = new frmMain();
fM.Location = this.Location;
fM.StartPosition = FormStartPosition.Manual;
fM.FormClosing += delegate { this.Show(); };
fM.Show();
this.Hide();
So say you are in the main applications forms Load event. Here you might launch your login screen
Then you might get whether the login passed from the relevant
logForm‘s accessor, so in thelogForm‘s Closing eventthen back in the main forms Load event after the
ShowDialog()above, you could check if the login passed, if it did not close the application or force a reattemptI hope this helps.