I have wanted to navigate through forms so when I client the buttonKlient I go to the Form2 then when I click control ‘x’ I go back to Form1 I got:
(the fk is 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();
}
Then in Form2
protected override void OnFormClosing(FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.WindowsShutDown) return;
var form1 = (Form1)Tag;
form1.Show();
Hide();
// DO WHATEVER HERE
}
When I click button1 the Form2 fk opens, then I close it by x control then click the button1 again and I get the exception ObjectDisposedException.
You’re hiding the form yes.. but the form is still being disposed. You need to add
e.Cancel = true;to cancel the form closing.