G
Guest
Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open
Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private formForm2 As New Form2
+ Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then
formForm2 = New Form2
End If
formForm2.Show()
formForm2.Activate()
End Sub
End Class
This works fine except when I close Form2 and click on the command button. I
get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in
system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat
I have two forms, Form1 and Form2. Form1 has a command button that will open
Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private formForm2 As New Form2
+ Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then
formForm2 = New Form2
End If
formForm2.Show()
formForm2.Activate()
End Sub
End Class
This works fine except when I close Form2 and click on the command button. I
get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in
system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat