I am working on a project (simple phonebook) for personal use.
Basically, I have got three forms: Main (the main one), Settings (the one used for configuring settings) and Login (the login form, which should start only if the user checked the option to be asked for the password on startup). Just to make the things clear: when the .EXE file is started it should load the Main form, unless the option to ask for pass is checked (Properties.Settings.Default.AskForPass == true) - when it should run the Login form first.
Here is what the login form looks like:

I have no idea how to make things work in the proper way.
I have tried to change the line in Program.cs from Main to Login:
namespace Phonebook
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}
}
}
and then if the user enters the right username and password and clicks the OK button:
private void button1_Click(object sender, EventArgs e)
{
if (txtUsername.Text == Properties.Settings.Default.MyUsername && txtPassword.Text == Properties.Settings.Default.MyPassword)
{
Main f1 = new Main();
Login f3 = new Login();
f1.Show();
f3.Close();
}
else
{
DialogResult dialogResult = MessageBox.Show("Wrong password! Do you want to try again?", "Warning", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Retry)
{
return;
}
else if (dialogResult == DialogResult.Cancel)
{
this.Close();
}
}
}
the login form stays in the background, as you can see here:

I would like the Login form to be closed, so it doesn't appear in the background. The problem is that now the Login form is the main one and if I try to close it, the whole application shuts down.
I have tried changing the owner but had no success doing so.
Any ideas? Please, help!