title: windows forms closing immediately when opened
body: <p>When I open a new form from my login screen, it logs the user in, shows the form then instantly disappears???</p>
  
  <p>Here is my code for the relevant parts:</p>
  
  <pre><code>string checkAdmin = "select * from Logins where Name = @userName and UserType ='Admin'";
  string checkUser = "select * from Logins where Name = @userName and UserType ='User'";
  using (var connection = new SqlConnection(@"server=.\SQLEXPRESS; database=loginsTest;Trusted_Connection=yes"))
  {
     using (var checkAdminCommand = new SqlCommand(checkAdmin, connection))
     {
        //guessing at the column length here. Use actual column size instead of 20
        checkAdminCommand.Parameters.Add("@username", SqlDbType.NVarChar, 50).Value = userNameBox.Text;
        connection.Open();
  
        if (checkAdminCommand.ExecuteScalar() != null)
        {
           adminScreen admnscrn = new adminScreen();
           admnscrn.Show();
           this.Close();
           return;
        }
  
        else
        {
        }
     }
  
  using (var connection = new SqlConnection(@"server=.\SQLEXPRESS; database=loginsTest;Trusted_Connection=yes"))
  {
     using (var checkUserCommand = new SqlCommand(checkUser, connection))
     {
        //guessing at the column length here. Use actual column size instead of 20
        checkUserCommand.Parameters.Add("@username", SqlDbType.NVarChar, 50).Value = userNameBox.Text;
  
        connection.Open();
        if (checkUserCommand.ExecuteScalar() != null)
        {
           userScreen usrscrn = new userScreen();
           usrscrn.Show();
           this.Close();
        }
  
        else
        {
           MessageBox.Show("Invalid details, try again");
           passwordBox.Text = "";
        }
     }
  }
  </code></pre>
  
  <p>So when I open usrscrn or admnscrn, it flicks up and goes straight back off again? I've tried researching, I've used Application.Run(userScreen()); etc, it just throws an exception saying something about a second message loop?</p>
  
  <p>I have created a new screen, set it as MDI, and entered this code:</p>
  
  <pre><code>        private void MDI_Form_Load(object sender, EventArgs e)
      {
          Form1 loginscrn = new Form1();
          loginscrn.Show();
      }
  </code></pre>
  
  <p>my program.cs file contains this code:</p>
  
  <pre><code> static void Main()
      {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new MDI_Form());
      }
  </code></pre>
  
  <p>will this work??</p>