In the main form Load() event you have to invoke the Login form and to manage the result of the login: to let the main form to show or not (based on the user input).
Here is an example:
private void FileManagerForm_Load(object sender, EventArgs e)
{
this.Hide();
if (!DoLogin())
{
this.Close();
return;
}
this.Show();
}
private bool DoLogin()
{
Logout();
Des3 des3 = new Des3();
LoginForm form = new LoginForm()
{
UserName = Settings.Default.UserName,
Password = String.IsNullOrEmpty(Settings.Default.Password) ? string.Empty : des3.Decrypt(Settings.Default.Password),
CheckCredentials = Settings.Default.RememberMe,
LoginFormParent = this
};
if (DialogResult.OK != form.ShowDialog() || this.SessionGuid == null)
return false;
...
}