' 获得子窗体数量,判断是否有要打开的子窗体
Private Function GetInstanceState(ByVal Name As String) As Boolean
Dim i As Integer = Me.MdiChildren.Length
For i = 0 To Me.MdiChildren.Length - 1
'循环判断是否有名为name的子窗体
If Me.MdiChildren(i).Name = Name Then
'存在名为name的子窗体
Me.MdiChildren(i).Focus()
'子窗体获得焦点并返回True
Return True
End If
Next
Return False
'不存在名为Name的子窗体返回False
End Function
Private Sub .......
'调用子窗体的事件
If GetInstanceState(子窗体名) Then
Exit Sub
End If
Dim ChildFrm As Form
ChildFrm = New 子窗体名
ChildFrm.MdiParent = Me
ChildFrm.Show()
End Sub