Only One Instance of MDI Child Form

In my MDI parent, I can launch many different forms as many times as I like (hence, MDI). However, for one form there should only be one instance. How do I do that? I tried a couple of the solutions (via search on EE), but they did not work. Any ideas?
LVL 9
GivenRandyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is one approach:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not loadMDIChild("Form2") Then
            Dim f As New Form2
            f.Name = "Form2"
            f.MdiParent = Me
            f.Show()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Not loadMDIChild("Form3") Then
            Dim f As New Form3
            f.Name = "Form3"
            f.MdiParent = Me
            f.Show()
        End If
    End Sub

    Private Function loadMDIChild(ByVal childName As String) As Boolean
        Dim f As Form
        For Each f In Me.MdiChildren
            If f.Name.Equals(childName) Then
                If f.WindowState = FormWindowState.Minimized Then
                    f.WindowState = FormWindowState.Normal
                End If
                f.Focus()
                Return True
            End If
        Next
        Return False
    End Function

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RonaldBiemansCommented:
If it is just for one kind of form you could also just set a boolean value in your parent and check that
0
GivenRandyAuthor Commented:
That is my fallback. With all the functionality in the .NET Framework, I figured there must be a more straight-forward way that I was overlooking.
0
RonaldBiemansCommented:
Well I haven't found another way then ones Idle_mind and I suggested.
0
GivenRandyAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.