Controlling to prevent the window from opening again in MDIForm

2

How do I check if a window has been opened? If it has been opened, bring it forward, otherwise open a new window. That is, I need to control the windows, checking them so that only one is open.

    
asked by anonymous 07.09.2014 / 19:48

1 answer

1

Easy. In the event where you are currently opening the window, place the following condition:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim fEncontrou As Boolean = False
    For Each f As Form In Application.OpenForms
        If f.Name = "Form2" Then
            fEncontrou = True
            f.BringToFront()
            f.Activate()
            Exit For
        End If
    Next
    If Not fEncontrou Then Form2.Show()
End Sub
    
26.09.2014 / 15:33