Hey

This is going to be hard to explain but oh well....


I have a form with a menu. When I hit option one, it opens another form (form2) inside that same form (mdiparent). When I hit X on form2, then try to open it again from the original form with a menu thru the menu, It says it cant access a disposed object. Here is the code:

Form1:

Public Class Form1
    Dim f As New Form2

    Private Sub arandomname(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stripMenuItem.Click
        f.MdiParent = Me
        f.Show()
    End Sub
....

Form2:
?

(The code above is just example. Dont worry about the names just the f and all that)
What do I do to fix it or make it all work?

Private Sub arandomname(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stripMenuItem.Click

  If IsNothing(f) OrElse f.IsDisposed Then
            f = New Form()
            f.MdiParent = Me
            f.Show()
   End If
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.