Controlling to prevent window from opening again in Mdiform

Asked

Viewed 321 times

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.

  • Explain better what you want to know. You want to control so that only one application instance is opened?

  • http://sanity-free.org/143/csharp_dotnet_single_instance_application.html

1 answer

1

Easy. In the event 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.