SlammingRumJoseph
asked on
VB.Net winFORMS - Open form only if it isnt open already
Guys,
I am writing a Windows App and I need to figure out a way of determining if forms are currently running. There is a form that will show another form which is userd to create a database record - but only if the form isnt already show.
How do i do this?
Thanks,
Joe
I am writing a Windows App and I need to figure out a way of determining if forms are currently running. There is a form that will show another form which is userd to create a database record - but only if the form isnt already show.
How do i do this?
Thanks,
Joe
If you are using MDI........
‘Determine if form already exists
Dim frmTest As Form
Dim blnFound As Boolean = False
‘Does form already exist?
For Each frmTest In Me.MdiChildren
With frmTest
If .Name = “frmSummary” Then
.Activate() ‘Activate previous instance
blnFound = True
End If
End With
Next
If Not blnFound Then
Dim frmSummaryInstance As New frmSummary()
With frmSummaryInstance
.MdiParent = Me
.Show()
End With
End If
‘Determine if form already exists
Dim frmTest As Form
Dim blnFound As Boolean = False
‘Does form already exist?
For Each frmTest In Me.MdiChildren
With frmTest
If .Name = “frmSummary” Then
.Activate() ‘Activate previous instance
blnFound = True
End If
End With
Next
If Not blnFound Then
Dim frmSummaryInstance As New frmSummary()
With frmSummaryInstance
.MdiParent = Me
.Show()
End With
End If
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
this may seem like a silly statement, but could you not show this form modally, until the record is added, then it can be closed and return to your main form... this way two forms can't be shown. Obviously you can't go back to your main form while you're in this dialog form, but depending on what you need it for, this could be an easy solution
not a silly statement at all S-Twilley :-)
If Me.OwnedForms.Length = 0 Then
Dim x As New Form2
x.Owner = Me
x.Show()
Else
Me.OwnedForms(0).Show()
End If
this will work if only one other form is showed from the owner form.