|
-
Dec 29th, 2010, 07:37 AM
#1
Thread Starter
New Member
[RESOLVED] Opening MDI Child forms
Dear Sir/Madam,
In a MDI application, for opening a form in the MDI, I am using the following code
Code:
Private Sub RoleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RoleToolStripMenuItem.Click
Dim lobj_ChildForm As frmRole
'Check if form is already open
lobj_ChildForm = Nothing
For Each lobj_OpenForm In Me.MdiChildren()
If lobj_OpenForm.Name = frmRole.Name Then
lobj_ChildForm = lobj_OpenForm
End If
Next
If Not (lobj_ChildForm Is Nothing) Then
lobj_ChildForm.BringToFront()
Else
lobj_ChildForm = New frmRole
lobj_ChildForm.MdiParent = Me
lobj_ChildForm.Show()
End If
End Sub
As you can see, I need loopong through all the open child forms. Is this the only way? Or is there a better technique?
Regards,
Partha
-
Dec 29th, 2010, 09:25 AM
#2
Re: Opening MDI Child forms
It appears that you only want one instance of frmRole open at a time. This is one situation where I would genuinely support using a default instance. Your code should simple be:
vb.net Code:
frmRole.MdiParent = Me frmRole.Show() frmRole.Activate()
That will handle all three possible situations, i.e. no instance has ever been displayed, an instance is currently displayed and an instance has been displayed but has been closed.
For more information on default instances, follow the Blog link in my signature and check out my post on the subject.
-
Dec 29th, 2010, 11:52 PM
#3
Thread Starter
New Member
Re: [RESOLVED] Opening MDI Child forms
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
|