Today, I'm using a lot these functions but I have already found several problems about them. My program is so structured:
This is Form 1:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
...
...
edit = new Button();
edit.Click += new EventHandler((s, e) => edit_mode(s, e,x,y,c,z)); //x, y, c, z are some variables that I need to pass to purposes of this software.
this.Controls.Add(edit);
}
void edit_mode(object sender, EventArgs e, string x,string y, int c, int z)
{
...
...
Form edits = new Form4();
edits.Show();
this.Hide();
}
}
and this is Form 4:
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
...
...
...
Form backs= new Form1();
backs.Show();
this.Close();
}
The target of this piece is the follow: when I enter in the "edit_mode" function, Form1 has to disappear to display a new Form (Form4).
I' ve searched a lot here, but no solutions worked for me: Compiler doesn't report me errors, so when I debug this piece of code all seems working; But when it arrives to edits.Show(); (in Form1) it says: ObjectDisposedException error and I don't understand why. I've tried to replace that this.Close() with this.Hide() and the program runs good until the this.Hide() function of Form4 is performed: In fact, when Form4 appears and performs its code it stops itself to this.hide() and the form4 doesn't disappear (while appear the Form1). I've tried also to create a Button in form4 and to move here the code to open the Form1.. and it works great! but I've only a problem: I don't want the user to press a button to make this working. So I need to make automatic this "Form change".
Any idea about this problem?