By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

System.ObjectDisposedException: Cannot access a disposed object.

P: 36
Hai i am working on vb.net.
In my application I created four forms.Those are first.vb,f1.vb,f2.vb and f3.vb
In firstvb I added 3 checkboxes and a "display" button.The 3 checkboxes are used to display the forms f1,f2 and f3.If first checkbox is checked then it displays the f1 form.Similarly for f2 and f3 also.I kept all this code in the display button click event.In f1.vb,f2.vb and f3.vb I added back and next buttons. I wrote some code to display the previous form into Back button click event of each form. For this I am using a public function main1() in first.vb.If i click on back button at run time, it gets this error System.ObjectDisposedException: Cannot access a disposed object.

This is the code behind first.vb

Public Class first
Public Shared back As System.Windows.Forms.Form
Public Shared Function main1(ByVal f1 As System.Windows.Forms.Form) As System.Windows.Forms.Form
Return (f1)
End Function
Private Sub bdisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bdisplay.Click
Me.Visible = False
If (f1dchk.Checked = True) Then
back = main1(Me)
f1.Show()
Else
If (f2dchk.Checked = True) Then
back = main1(Me)
f2.Show()
Else
If (f3dchk.Checked = True) Then
back = main1(Me)
f3.Show()
End If
End If
End If

End Sub
Private Sub first_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class

i wrote this code behind f1.vb

Public Class f1

Private Sub f1back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f1back.Click
first.back.Show()
first.back = first.main1(first.back)
End Sub

Private Sub f1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

End Sub

Private Sub f1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Private Sub f1next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f1next.Click
Me.Close()
If (first.f2dchk.Checked = True) Then
first.back = first.main1(Me)
f2.Show()
Else
If (first.f3dchk.Checked = True) Then
first.back = first.main1(Me)
f3.Show()
End If
End If
End Sub
End Class

I wrote this code behind f2,vb

Public Class f2
Private Sub f2back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f2back.Click
first.back.Show()
first.back = first.main1(first.back)
End Sub
Private Sub f2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

End Sub

Private Sub f2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Private Sub f2next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f2next.Click

Me.Close()
If (first.f3dchk.Checked = True) Then
first.back = first.main1(Me)
f3.Show()
End If
End Sub

End Class

I wrote this code behind f3.vb

Public Class f3

Private Sub f3_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

End Sub

Private Sub f3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub f3back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f3back.Click
first.back.Show()
first.back = first.main1(first.back)
End Sub


Private Sub f3next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles f3next.Click
Me.Close()
End Sub
End Class

Can anyone help me?
Dec 24 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.