Creating a login form that will then proceed to the main form if the credentials are correct. Here is the basic pseudocode:
ShowLoginForm()
if (DialogResul
why not create main form and then show login modal dialog. Then you could check what to do.
How about setting the DialogResult to None in the SubmitButton event handler? Something like:
private void loginButton_Click(object sender, EventArgs e)
{
if (isValidCredentials())
DialogResult = DialogResult.OK;
else
{
MessageBox.Show("Failed to login or some other error");
DialogResult = DialogResult.None;
}
}
Try this
LoginForm loginForm = new LoginForm();
do {
if (loginForm.ShowDialog() == DialogResult.Cancel) {
return; // Ends application
}
} while (CheckCredentials() != VALID)
Application.Run(new AutoSignerForm());
I would do the following:
in Program.cs show the loginForm as a dialog
LoginForm login_form = new LoginForm();
if(login_form.ShowDialog() == DialogResult.OK) {
Application.Run(new MainForm());
}
in LoginDialog, handle the click event on "Login" button (or whatever is named)
// replace with the actual login
if(textBoxUsername.Text == "my user" && textBoxPassword.Text == "my pass") {
// save the user has logged in somewhere
// set the dialog result to ok
this.DialogResult = DialogResult.OK;
// close the dialog
this.Close();
} else {
// login failed
MessageBox.show("Login failed");
// do not close the window
}
Now, you will keep the LoginDialog shown until the user enters valid credentials or he gives up trying and the application closes. This way you will have only one instance of the LoginForm and it will be a nice user experience. Also, you can be sure that the MainForm is not initialized and shown without the user logging in successfully.