父窗体和子窗体的显示(vb.net)

首先写一个模块,其作用是检验一个子窗体是否已被实例化。

Module InstanceState

'检验一个窗体是否被实例化

Public Function GetInstanceState(ByVal name As String) As Boolean

Dim i As Integer = MDIMain.MdiChildren.Length

For i = 0 To MDIMain.MdiChildren.Length - 1

If MDIMain.MdiChildren(i).Name = name Then

MDIMain.MdiChildren(i).Focus()

Return True

End If

Next i

Return False

End Function

End Module

然后,在父窗体对子窗体的调用事件中设置子窗体置顶和是否在任务栏中显示的属性。

If GetInstanceState(form1.Name) Then

Exit Sub

End If

Dim frm1 As New form1

frm1.MdiParent = Me

frm1.Show()

frm1.TopMost = True

frm1.ShowInTaskbar = False

你可能感兴趣的:(VB.NET)