title: C# closing a form on button Click
body: <p>I am trying close the form after button1_Click, I tried using this.Close() in several spots, but it is not working. I want the button click to open a new Form called newDB. But when using this.Close() it will only close the form and not open up my new form. Is there any other way of doing this so that I can close the first form and still open up the newDB form? </p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      try
      {
          conn = new SqlCeConnection(@"Data Source=|DataDirectory|\Baseball.sdf; Persist Security Info=False;");
  
          DB newDB = new DB();
          newDB.ShowDialog();  
          this.Close();  
      }
      catch (Exception error)
      {
          MessageBox.Show("Could not connect to database!\n" + error, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
  
      // this.Close();
  }
  </code></pre>