我想在 button1_Click 事件之后关闭表单,我尝试在几个位置使用 this.Close(),但它不起作用。我希望按钮点击能打开一个名为 newDB 的新表单。但是当使用 this.Close() 时,它只会关闭表单而不打开我的新表单。是否有其他方法可以做到这一点,以便我可以关闭第一个表单并仍然打开 newDB 表单?
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();
}