I want to ask this. I have a form this form can control 4 more forms. When i click on the "open form 1" button it is okay but when i clicked "open form 2 " i getting some problem.
my codes like
public Form1()
{
InitializeComponent();
}
Form2 ac = new Form2();
Form3 ac2 = new Form3();
private void button1_Click(object sender, EventArgs e)
{
ac2.Close();
ac.Show();
}
private void button2_Click(object sender, EventArgs e)
{
ac.Close();
ac2.Show();
}
error tag = System.ObjectDisposedException (BUTTON 1 CLICK AFTER BUTTON 2 CLICK)
When you
Close
a form, the form object gets disposed and hence you wouldn't be able to callShow
on the disposed object. Read about Form.Close() here.You should be using
Hide
method instead ofClose
on clicking the buttons, which will only hide the form from the user. Modify your functions as follows:OR
Create new instance of form on button click handlers as follows: