Results 1 to 3 of 3

Thread: [RESOLVED] Opening MDI Child forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    11

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. frmRole.MdiParent = Me
    2. frmRole.Show()
    3. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    11

    Re: [RESOLVED] Opening MDI Child forms

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width