0

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
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by bluehangook629
0
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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.