I want to open a window inside my MDI and only open one on VB

Viewed 39

I want to open a window inside my MDI and only open one, when I open my child window it opens endlessly

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles                    MyBase.Load

End Sub

It's my first window that I want to open and I don't want it to open once

Private Sub mnuProgramme_Click(sender As Object, e As EventArgs) Handles mnuProgramme.Click
    Try
        Dim frm As New frmProgramme
        frm.MdiParent = Me
        frm.Show()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

This is my second window that I want to open and I don't want it to open once and I would like to close frmProgramme if it is already open

Private Sub mnuEtudiants_Click(sender As Object, e As EventArgs) Handles mnuEtudiants.Click
    Try
        For Each f As frmProgramme In Me.MdiChildren
            f.Close()
        Next
        Dim frm1 As New frmEtudiants
        frm1.MdiParent = Me
        frm1.Show()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

End Class

enter image description here

1 Answers

So I have tryied this but I have trouble with the MdiChildren.Length when opening the other tab. we can have the 2 tab but only one of each.

maybe we need to count by the name of the children dont know if its possible?

its ok for one childform but if we try to open the other one..

Private Sub MnuProgramme_Click(sender As Object, e As EventArgs) Handles 
MnuProgramme.Click
    Dim frm As New FrmProgramme
    Dim frmalreadyopen As Boolean
    Try
        If Me.MdiChildren.Length = 0 Then
            frm.MdiParent = Me
            frm.Show()
        Else
            For Each frm In Me.MdiChildren
                If frm.Name.ToUpper = "FrmProgramme" Then
                    frmalreadyopen = True
                    Exit For

                End If
            Next
            If frmalreadyopen = False Then
                frm.MdiParent = Me
                frm.Show()
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

Private Sub MnuEtudiant_Click(sender As Object, e As EventArgs) Handles 
MnuEtudiant.Click
    Dim frm As New FrmEtudiant
    Dim frmalreadyopen As Boolean
    Try
        If Me.MdiChildren.Length = 0 Then
            frm.MdiParent = Me
            frm.Show()
        Else
            For Each frm In Me.MdiChildren
                If frm.Name.ToUpper = "FrmEtudiant" Then
                    frmalreadyopen = True
                    Exit For

                End If
            Next
            If frmalreadyopen = False Then
                frm.MdiParent = Me
                frm.Show()
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
Related