hello
today i start writing an application which uses mdi forms(its new to me). and i use the following code:(i set form1=idmdicontainer=true) , is this correct way to create mdi forms ?

further i write the code :
there i have 2 more forms (form2 and form 3)

 Private Sub RegisterToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RegisterToolStripMenuItem.Click
        Dim frm As New Form2
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub RegisterToolStripMenuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RegisterToolStripMenuItem1.Click
        Dim frm As New Form3
        frm.MdiParent = Me
        frm.Show()
    End Sub

on the first menu's click i wanna show form2 and on the other 's click i wanna show form3. when i click more times on these menus , these forms continue to load , and therfore i a lot forms load in the mdi form

here is what i want

when i want to open the form it should unload the current child form and then it should load the form.how can i do that ?

You can close a child form by using:

 Me.ActiveMdiChild().Close()

Me.ActiveMdiChild().Close()

okay it should work. But what i need is something different i want that first it should check if mdicontainer contains mdichild or not. if it contains then it should close the current child and then load the new child form.

now , with the code you provide , i got how to close the current child form but how can i decide if mdicontainer contains mdichild or not ?

O.K. this is the code to check for open child forms and to do something when there are open forms

Dim F As Form
For Each F In Forms
    If F.MDIChild Then
        ' It's a loaded MDIChild form
    End If
Next F

Sorry, my first reply was more for vb6. Thsi should work in vb.net

For Each frm As Form in Me.MdiChildren
  MessageBox.Show(frm.Name)
Next

after stressing more on this issue , i got the solution. here i would like to share it (in the hope that if somebody who is facing the same problem may get the solution here).
here is what i have done to solve the issue.
i create a form type object named activeform and then initialize it to me.ActiveMdiChild.And if activeform does not contain Nothing then it means there exist child form and therfore i unload it before loading new form.

here is the code:

Dim activechild As Form = Me.ActiveMdiChild
        If (Not activechild Is Nothing) Then
            Me.ActiveMdiChild.Close()
        End If
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.