B
bole2cant
The error I get is:
Cannot access a disposed Object named "Form2".
Object name "Form2".
Here is the sequence which gives the error.
Start program. Form1 comes up and has a button to choose Form2.
Go to Form2. Close Form2 when done. Now back on Form1.
Click button to go back to Form2. The error/exception comes up.
I originally got this error when using Me.Close(), so I changed it to Me.Hide() and everything was fine. Except now when the form is closed using the white X in the red button instead of the 'Close' button on Form2, I still get the error message. Apparently, clicking the white X is equivalent to Me.Close() and that won't let me re-open the form.
What am I missing here?
****Code in Form1
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Form2 As New Form2
Dim Form3 As New Form3
---------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
Form2.BringToFront()
End Sub
****Code in Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Hide()
End Sub
=============================
Cannot access a disposed Object named "Form2".
Object name "Form2".
Here is the sequence which gives the error.
Start program. Form1 comes up and has a button to choose Form2.
Go to Form2. Close Form2 when done. Now back on Form1.
Click button to go back to Form2. The error/exception comes up.
I originally got this error when using Me.Close(), so I changed it to Me.Hide() and everything was fine. Except now when the form is closed using the white X in the red button instead of the 'Close' button on Form2, I still get the error message. Apparently, clicking the white X is equivalent to Me.Close() and that won't let me re-open the form.
What am I missing here?
****Code in Form1
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Form2 As New Form2
Dim Form3 As New Form3
---------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
Form2.BringToFront()
End Sub
****Code in Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Hide()
End Sub
=============================