PDA

Click to See Complete Forum and Search --> : detecting my children


kerv21
Nov 20th, 2002, 11:03 AM
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. :confused:

hellswraith
Nov 20th, 2002, 01:55 PM
Are form1 and form2 both children?

Pirate
Nov 20th, 2002, 01:59 PM
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.



Private Sub Form1_Load(ByVal sender As System.Object _
, ByVal e As System.EventArgs) Handles MyBase.Load
Form2Child.MdiParent = Me
Form2Child.Show()
End Sub



in the general declaration of the form write this :

Dim Form2Child As New Form2()


the function :

Private Function DetectChildForm(ByVal frm As Form) 'As Boolean
Dim x As Exception
Try
If ActiveMdiChild.Name = ActiveMdiChild.Name Then
MsgBox("active")
Else
MsgBox("not active")
End If

Catch x
MsgBox(x.ToString)
End Try
End Function




then call it but it has only one bug :rolleyes: 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.

kerv21
Nov 20th, 2002, 02:00 PM
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

Pirate
Nov 20th, 2002, 02:08 PM
I tried your code , I got exception error

kerv21
Nov 20th, 2002, 02:33 PM
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

Pirate
Nov 20th, 2002, 02:38 PM
same error :confused: