want to open a single copy of a form on a event
-
Hi all.... i want to open form on a event. if form is already opened it should not open again on that event else should open again. for example i tried for a button click event ... // member of form1 class Form2 obj = new Form2(); private void button1_Click(object sender, System.EventArgs e) { obj.Show(); } 1) if i declare the form2 obj inside the function its opening a new copy of form2 for each click event 2) or if i declare it as a member of form1 class and if i close the form2 and againg tried to open it, it throws the foll.. exception... An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll Additional information: Cannot access a disposed object named "Form1". :confused: sathy
-
Hi all.... i want to open form on a event. if form is already opened it should not open again on that event else should open again. for example i tried for a button click event ... // member of form1 class Form2 obj = new Form2(); private void button1_Click(object sender, System.EventArgs e) { obj.Show(); } 1) if i declare the form2 obj inside the function its opening a new copy of form2 for each click event 2) or if i declare it as a member of form1 class and if i close the form2 and againg tried to open it, it throws the foll.. exception... An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll Additional information: Cannot access a disposed object named "Form1". :confused: sathy
Hello, You can try following code. Define the Form2 object outside the function as 'global' variable for the Form1 class.
Form2 obj;
..... Write this code in the button click event handlerprivate void button1_Click(object sender, System.EventArgs e) { if(obj == null || obj.IsDisposed) obj = new Form2(); obj.Show(); }
HTH. Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net -
Hello, You can try following code. Define the Form2 object outside the function as 'global' variable for the Form1 class.
Form2 obj;
..... Write this code in the button click event handlerprivate void button1_Click(object sender, System.EventArgs e) { if(obj == null || obj.IsDisposed) obj = new Form2(); obj.Show(); }
HTH. Cheers :) Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net