C# 浏览表单c时的ObjectDisposeException#
我想浏览表单,所以当我客户端ButtonClient时,我转到表单2,然后当我单击控件“x”时,我回到表单1,我得到: (fk的C# 浏览表单c时的ObjectDisposeException#,c#,forms,navigation,C#,Forms,Navigation,我想浏览表单,所以当我客户端ButtonClient时,我转到表单2,然后当我单击控件“x”时,我回到表单1,我得到: (fk的fk是Form2) 然后在Form2 private void button1_Click(object sender, EventArgs e) { if (fk == null) fk = new OknoKlient(); fk.Tag = this;
fk
是Form2
)
然后在Form2
private void button1_Click(object sender, EventArgs e) {
if (fk == null)
fk = new OknoKlient();
fk.Tag = this;
fk.Show(this);//here is ObjectDisposedException
Hide();
}
protected override void OnFormClosing(FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.WindowsShutDown) return;
var form1 = (Form1)Tag;
form1.Show();
Hide();
// DO WHATEVER HERE
}
当我点击button1
时,Form2 fk
打开,然后我通过x
控件将其关闭,然后再次点击按钮1,我得到异常ObjectDisposedException
保护覆盖void OnFormClosing(FormClosingEventArgs e){
protected override void OnFormClosing(FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.WindowsShutDown) return;
e.Cancel = true; // <---------------------- this
var form1 = (Form1)Tag;
form1.Show();
Hide();
// DO WHATEVER HERE
}
如果(e.CloseReason==CloseReason.WindowsShutDown)返回;
e、 Cancel=true;//@gdoron很抱歉,当我在OnFormClosing方法中使用Close()而不是Hide()时,我得到了StackOverflow。您使用的是两个不同的ID吗?