I am building a MDI Windows Forms application where I have placed a
splitcontiner. Using tabs I am trying to load different forms into the split
container. Everything works fine, but for some reason the application hangs
on exactly the 10th time a from is loaded into the splitcontainer (can
repeat this). I have gone back to basics and removed all code from the child
forms being loaded and still the applcaition hangs on the 10th time a form
is loaded.

If anyone can see any logic in why this is happening or can take a moment to
look at the code below to se if I am doing something obvious wrong, that
would be much appreciated

Niclas

Public Class Main

Private Sub Lable1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Lable1.Click
LoadForm(New frm1, SplitContainer1.Panel2)
End Sub
Private Sub Lable2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Lable2.Click
LoadForm(New frm2, SplitContainer2.Panel2)
End Sub

Public Sub LoadForm(ByVal frmToLoad As Form, ByVal tab As Control)
Try
Dim Frm As Form

For Each Frm In tab.Controls
Frm.Dispose()
Next

Frm = frmToLoad
Frm.TopLevel = False
Frm.Parent = tab
Frm.Show()

Catch ex As Exception
MessageBox.Show(ex.Message, "An error occured",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub

Public Sub DisposePanelForm(ByVal TargetPanel As Panel)
Dim f As Form
For Each f In TargetPanel.Controls
f.Dispose()
Next
End Sub

Private Sub SideBar_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Lable2.MouseEnter, Lable1.MouseEnter
Dim lbl As Label

lbl = CType(sender, Label)
lbl.ForeColor = Color.Yellow


End Sub
Private Sub SideBar_MouseLeft(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Lable2.MouseLeave, Lable1.MouseLeave
Dim lbl As Label

lbl = CType(sender, Label)
lbl.ForeColor = Color.White

End Sub

Private Sub Tab1_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Tab1.Enter

If SplitContainer1.Panel2.HasChildren = False Then
LoadForm(New frm3, SplitContainer1.Panel2)
End If
End Sub

Private Sub Tab2_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Tab2.Enter
If SplitContainer2.Panel2.HasChildren = False Then
LoadForm(New frm4, SplitContainer2.Panel2)
End If
End Sub
Private Sub Tab2_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Tab2.Leave
DisposePanelForm(SplitContainer2.Panel2)
End Sub
Private Sub Tab1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Tab1.Leave
DisposePanelForm(SplitContainer1.Panel2)
End Sub
End Class