Cannot access a disposed object named "Form2"

sgfreestyler

Member
Joined
Aug 6, 2005
Messages
6
Programming Experience
1-3
======================================================
Dim FormTwo As New Form2
Public Shared tx As TextBox

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

tx = TextBox4
FormTwo.ListBox1.Items.Add(tx.Text)


End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
FormTwo.Show()
End Sub

=====================================================


from the code, u can see that i have add the text from textbox4 to form2's listbox. this part is fine. But the problem i am facing is after i close my form2, i cannot open again .. it say "Cannot access a disposed object named "Form2". how do i correct this. i wan my form2 to be able to close and open freely with all the text i have added in the listbox still remain there.

can any1 help ..
tks
 
Hi,

i think you want your form not showing for a while!?

Did you use fromTwo.close() for this!?

this Method will remove the form Object from your memory and its normal when you can't access later!
Instead use

formTwo.hide()
formTwo.show()

i hope i couls help you
 
Christian is alright ... also note that in order to reopen closed form (if you want to avoid hide/show methods) you should declare the form object ones again / Dim FormTwo As New Form2 or if it's public variable you could do that as it follows:
FormTwo = new Form2
FormTwo.Show()


Cheers ;)
 
Back
Top