You can display the login form as a dialog and, if you want to log in, you can run the main form as:
static class Program { public static bool isValid = false;
in your FrmLogin, check the user and set DialogResult as Ok . Here I did this on a button click event.
private void btnLogin_Click(object sender, EventArgs e) { Program.isValid= true; // impliment this as method if(Program.isValid) { this.DialogResult = DialogResult.OK; // or this.Close(); } else { //else part code } }
source share