G
Guest
Hello – I’m relatively new to VB and I’m not getting how to do Dispose
correctly from my readings.
I have an application with 3 Forms (with a lot of logic going on within
each): Form1, Form2, and a 3rd Form which is a dialog.
- Form 1 at the top has:
Dim frmTwo As New Form2
(and upon a button click, shows Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
frmTwo.Show()
- Form 2, upon a button click, shows a Dialog with ShowDialog. I can show
and close and re-show that Dialog all I want. After the ShowDialog statement
I have a Dispose() statement for the Dialog form.
Here’s the problem: if I close Form2, and then later I try to Show Form2
again (by clicking the button on Form1) I get the error:
“unhandled exception System.ObjectDisposedException in
system.windows.forms.dll.
Can’t access disposed object named Form2 “.
I’ve tried putting Dispose & Finalize in various places, but I need some
advice here.
Thanks so much.
correctly from my readings.
I have an application with 3 Forms (with a lot of logic going on within
each): Form1, Form2, and a 3rd Form which is a dialog.
- Form 1 at the top has:
Dim frmTwo As New Form2
(and upon a button click, shows Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
frmTwo.Show()
- Form 2, upon a button click, shows a Dialog with ShowDialog. I can show
and close and re-show that Dialog all I want. After the ShowDialog statement
I have a Dispose() statement for the Dialog form.
Here’s the problem: if I close Form2, and then later I try to Show Form2
again (by clicking the button on Form1) I get the error:
“unhandled exception System.ObjectDisposedException in
system.windows.forms.dll.
Can’t access disposed object named Form2 “.
I’ve tried putting Dispose & Finalize in various places, but I need some
advice here.
Thanks so much.