I need help with managing my forms. below is a sample code for one of my button that opens a new form on button click. But today while I was testing the application, I found out that everytime I have button click, I get a new instance of the same form. which means that I can end up with 20 open forms of the same. I was wondering if there is a way to see if a form is already open so I can handle the event only when there is no other forms open. Thanks

Private Sub btnHome_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnHome.ItemClick
        Dim MDI_Home As New frmHome() With {.MdiParent = Me}
        MDI_Home.Show()
        MDI_Home.MaximizeBox = True
    End Sub
Private Sub btnHome_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnHome.ItemClick

For Each frm In My.Application.OpenForms
			If TypeOf frm Is frmHome Then 'form is already open
                                frm.show
				Exit Sub 
			End If
Next

        Dim MDI_Home As New frmHome() With {.MdiParent = Me}
        MDI_Home.Show()
        MDI_Home.MaximizeBox = True
End Sub

Great! thanks Geek

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.