Search code examples
vb.netwinformsmdi

Avoid opening of duplicate mdi child


I need to open one instance of a MDI child in VB.Net vs2008...this code opens several duplicates of the same MDI child; I got this answer Prevent duplicate MDI children forms for c# but didnt find one for VB.Net vs 2008

Dim myChild As New Form1()
myChild.MdiParent = Me
myChild.Show()

Solution

  • This is the VB.Net version of Fredrik Mörk's code:

    For Each f As Form In Application.OpenForms
      If TypeOf f Is Form1 Then
        f.Activate()
        Return
      End If
    Next
    
    Dim myChild As New Form1
    myChild.MdiParent = Me
    myChild.Show()