Click to See Complete Forum and Search --> : how to detect an already open form
jkw119
Nov 6th, 2002, 08:20 AM
I have probably a relatively simple question... (at least one would think)
IN my menu, there is an item that opens a form. I would like to put some code so that, if the user clicks it twice, instead of opening two forms, the already open form is just selected and brought to the front of everything. Does anyone have any suggestions? This is the menu code
Dim SegmentInfoForm As New frmSegmentInfo()
SegmentInfoForm.Show()
System.Windows.Forms.Application.DoEvents()
Thanks,
jkw119
Fat_N_Furry
Nov 6th, 2002, 10:20 AM
'In the general declarations
Dim booFormLoaded as Boolean = False
'In your sub
If booFormLoaded = False then
Dim SegmentInfoForm As New frmSegmentInfo
SegmentInfoForm.Show()
System.Windows.Forms.Application.DoEvents
booFormLoaded = True
Else
SegmentInfoForm.Focus()
End If
gL,
Furry
csvax
Nov 6th, 2002, 03:12 PM
Try this
' defined in a module
public SegmentInfoForm As frmSegmentInfo()
In the click menu event :
if SegmentInfoForm is nothing or segmentinform.isdispose() then
SegmentInfoForm = new frmSegmentInfo()
endif
SegmentInfoForm.show()
SegmentInfoForm.topmost =true
308holes
Nov 6th, 2002, 04:09 PM
[/code]
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click, CmnuDisplayChild.Click
'Instantiate a child
LoadForm("frmChild")
End Sub
Private Sub LoadForm(ByVal strFormName As String)
'Load form or activate if it already exists
Dim frmForms() As Form = Me.MdiChildren
Dim intIndex As Integer
Dim blnFound As Boolean
'Does it exist?
For intIndex = 0 To frmForms.GetLength(0) - 1
If frmForms(intIndex).Name = strFormName Then
blnFound = True
frmForms(intIndex).Activate()
End If
Next
If Not blnFound Then
Select Case strFormName
Case "frmChild"
Dim frmChild As New ChildForm()
With frmChild
.MdiParent = Me
.Name = "frmChild"
.Show()
End With
End Select
Me.LayoutMdi(MdiLayout.Cascade)
End If
End Sub
[/code]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.