I am having trouble hiding my main form for a login form. Once user has logged in to close login form and show main form.
I have been confusing myself that much I ha
Use ShowDialog() to open the login form. Then you don’t need to hide or disable the Mainform yourself. In fact, if you want the login form to appear at the beginning of the application, consider showing it before even loading the Mainform:
static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
DialogResult result;
using (var loginForm = new LoginForm())
result = loginForm.ShowDialog();
if (result == DialogResult.OK)
{
// login was successful
Application.Run(new Mainform());
}
}
Inside your login form, in button1_Click, use
DialogResult = DialogResult.OK;
to close the login form and pass the OK result to the Mainform.
There is no need for Dispose().