-
menus interaction
Hi:
I created 2 menus named: Form1, Form2 in the same solution,respectively.
so I created a reference of Form2 and a button in Form1.
Form2 myForm = new Form2();
Now, the button event is myForm.Show();
When I ran it, click the button I got Form2, so I closed the Form2, but the problem appeared if I clicked button again, it gave me such message:
can't access a disposed object named "Form2",
Object name:"Form2.ShowDialog"
But if I changed to:
myForm.ShowDialog, then no problem
what happened?? :(
Thank you
-
My guess is that closing Form2 disposes ( destroys ) the form. So you might need to create a new Form2 every time.
-
My guess ...
>> so I closed the Form2
It sounds like you closed the form manually then clicked a button that references something in that form you just closed.
Don't close that form next time, see what happens & let us know
-
Ok, things are like that:
I click the button on Form1 to pop up Form2,
there is a reference of Form2:
Form myForm2 = new Form2();
inside the button event:
myForm2.Show();
when I ran it:
Form2 appeared:
there was a close button on the Form2's right top corner, so i closed, but when I clicked that button again, then I got that kind of error, why I can't click that "X" button:
but after I changed to myForm2.ShowDialog(). then no problem.
Strange..
-
and what is the command if I control the Form2 by Form1, let's say when I click the button on Form1, then one label is created on Form2.
I am quite newbie on C#
:):)