我有一個MDIParent,我打開了一個子窗口。如果點擊按鈕,我需要關閉當前的父項。所以我試過下面的代碼如何關閉當前窗體Winform C#
private void button_log_Click(object sender, EventArgs e)
{
MDIParent_Main obj = new MDIParent_Main(textBox_username.Text);
obj.Show();
this.Close();
}
問題是它關閉了MDIParent_Main和子窗體。 我的錯誤在哪裏?
如果'this'也是一個MdiParent,那麼這就是你的答案。你打開的表單屬於'this',所以關閉'this'關閉所有。 – DonBoitnott
您遇到的問題是您的應用程序正在關閉父窗口時結束。看看這個http://stackoverflow.com/questions/40962/how-do-i-close-a-parent-form-from-child-form-in-windows-forms-2-0 – Liath
@DonBoitnott,我認爲這是個好地方.Close()故意關閉父親 – Liath