Results 1 to 2 of 2

Thread: VB .net MDI Form question

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    6

    VB .net MDI Form question

    Hi guys,

    I am trying to determine whether the child form is opened before creating another instance of a form.


    The following code creates a new instance of form.


    Dim frm As New Form
    frm.MdiParent = Me ' Me is the container
    frm.Show()


    I don't want to create another instance of a form if the same form already opened. If the form already opened then I want to bring to the front.

    Thanks in advance

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    The way I do it is if I want to only have 1 instance of a form on a screen at any one time is to declare a private reference to the form inside the MDI parent, and just use that.

    e.g.

    VB Code:
    1. 'At form declarations
    2. Private m_Child As frmChild
    3.  
    4. 'Later on inside a click event
    5. If m_Child Is Nothing Then
    6.             m_Child = New frmChild
    7. ElseIf m_Child.Created = False Then
    8.            'Form has been disposed, need to create a new instance
    9.             m_Child = New frmChild
    10. End If
    11. m_Child.MdiParent = Me
    12. m_Child.Show()
    13. m_Child.Activate()

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