|
-
Nov 6th, 2002, 09:20 AM
#1
Thread Starter
Registered User
how to detect an already open form
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
VB Code:
Dim SegmentInfoForm As New frmSegmentInfo()
SegmentInfoForm.Show()
System.Windows.Forms.Application.DoEvents()
Thanks,
jkw119
-
Nov 6th, 2002, 11:20 AM
#2
Addicted Member
VB Code:
'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
 Eat long and prosper! 
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum! 
-
Nov 6th, 2002, 04:12 PM
#3
Lively Member
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
-
Nov 6th, 2002, 05:09 PM
#4
Hyperactive Member
[/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]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|