Hello
It depands to the
Workflow of the application.
I prefer it for
small applications:
1. Have a main form.
2. In Form_Load event:
LoginForm loginForm = new LoginForm();
this.AddOwnedForm(loginForm);
while (!loginForm.IsAuthenticated)
{
if (loginForm.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
{
this.Close();
break;
}
}
3. And a little change in LoginForm:
you need at least 2 extra properties:
public bool IsAuthenticated { get; set; }
public string UserName { get; set; }
Before closing the LoginForm check the userName and password and if they are ok, then
IsAuthenticated = true;
and
this.UserName = UserNameTextBox.Text;
In Click event of
Ok
or
Login
button, Set:
this.DialogResult = System.Windows.Forms.DialogResult.OK;
Specify the Cancel button