Results 1 to 7 of 7

Thread: detecting my children

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    113

    detecting my children

    In an MDI application is their any possible way to detect another child form ?

    Let's say for example I have form1 open and I want to see if form2 is currently open.


    Thanks for any help.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Are form1 and form2 both children?

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    here is the function I created that detects any Child Form whether it is active or not :

    all this code should be added in the parent MDI form.

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object _
    2. , ByVal e As System.EventArgs) Handles MyBase.Load
    3.         Form2Child.MdiParent = Me
    4.         Form2Child.Show()
    5.     End Sub

    in the general declaration of the form write this :
    VB Code:
    1. Dim Form2Child As New Form2()

    the function :
    VB Code:
    1. Private Function DetectChildForm(ByVal frm As Form) 'As Boolean
    2.         Dim x As Exception
    3.         Try
    4.             If ActiveMdiChild.Name = ActiveMdiChild.Name Then
    5.                 MsgBox("active")
    6.             Else
    7.                 MsgBox("not active")
    8.             End If
    9.  
    10.         Catch x
    11.             MsgBox(x.ToString)
    12.         End Try
    13.     End Function

    then call it but it has only one bug when you close the child form and call the function again it generates an error , (though it has one bug but i sent you to maybe get you started .
    so anyone know how to solve that.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    113

    [RESOLVED]

    Problem resolved:


    Using MDIChildren of the parent form to loop through all open child forms.


    Here is what I was able to get working for my situation:


    In an sub of form1
    -------------------------

    Dim f as form
    For each f in me.parent.MDIchildren
    If f.text = "form2"
    Do something here...
    endif
    Next f

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I tried your code , I got exception error

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    113
    Pirate,

    Here's exactly the way I am doing it with no prob's.


    Private sub ChildCheck()
    Dim f as Form

    For Each f in me.ParentForm.MDIChildren
    If f.text = "Form Title to Match" then
    ' Do something here

    Endif
    Next f
    End Sub

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    same error

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