I have an menu form that is an mdi container. When my app opens, it opens up the menu form. It then does:
which opens the login form. After login, the login form closes. On the main menu if they logout, the login button is re enabled. I want to do a check to make sure it isnt already open. This isnt just for this form, but others. I am trying to prevent multiple instances of forms from opening. I search the internet and found this:
So when I try to use this:
I get an error if the form is already open. On the if line, I get property can only be set to nothing. What am I doing wrong? How do I fix this?
I read something about default instances, but don't completely understand it. I thought that is what I was doing with Dim newmdichild As New frm_login, but i guess not.
Any help would be appreciated.
Oh and I am using VS 2010
VB.NET:
Dim newmdichild As New frm_login
newmdichild.MdiParent = Me
newmdichild.Show()
newmdichild.Left = (Me.Width / 2) - (newmdichild.Width / 2)
newmdichild.Top = (Me.Height / 2.5) - (newmdichild.Height / 2)
which opens the login form. After login, the login form closes. On the main menu if they logout, the login button is re enabled. I want to do a check to make sure it isnt already open. This isnt just for this form, but others. I am trying to prevent multiple instances of forms from opening. I search the internet and found this:
VB.NET:
Public Shared Function ChildFormOpen(ByRef ParentForm As Form, ByRef Childform As Form) As Boolean
' Used to find out if a child form is open in the parent container
' Usage:
' dim secForm as new secondform
' if childformopen(parentform,childform) then
' secform.activate
' else
' secform.mdiparent = me
' secform.show
' end if
' secform = nothing
Dim blnIsOpen As Boolean = False
Dim frm As Form
For Each frm In ParentForm.MdiChildren
If Childform.Name = frm.Name Then
Childform.Focus()
blnIsOpen = True
Childform = frm
Exit For
End If
Next
ChildFormOpen = blnIsOpen
frm = Nothing
End Function
So when I try to use this:
VB.NET:
Private Sub LogonBBI_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles LogonBBI.ItemClick
Call DisableMenu()
If ChildFormOpen(Me, frm_login) Then
Dim newmdichild As New frm_login
newmdichild.MdiParent = Me
newmdichild.Show()
newmdichild.Left = (Me.Width / 2) - (newmdichild.Width / 2)
newmdichild.Top = (Me.Height / 2.5) - (newmdichild.Height / 2)
End If
End Sub
I get an error if the form is already open. On the if line, I get property can only be set to nothing. What am I doing wrong? How do I fix this?
I read something about default instances, but don't completely understand it. I thought that is what I was doing with Dim newmdichild As New frm_login, but i guess not.
Any help would be appreciated.
Oh and I am using VS 2010