C # closing a form on a Click button

I try to close the form after button1_Click, I tried to use this.Close () in several places, but it does not work. I want a button to click a button to open a new form called newDB. But when using this.Close () it only closes the form and does not open my new form. Is there any other way to do this so that I can close the first form and open the newDB form?

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();
}
+4
source share
1 answer

ShowDialog , , , . , , this newDB, Form Load newDB, Close Window/Form, , .

Form, DB "" , , Close .

?

+3

All Articles