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:
Printable View
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:
Are form1 and form2 both children?
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:
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 :
VB Code:
Dim Form2Child As New Form2()
the function :
VB Code:
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.
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
I tried your code , I got exception error
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
same error :confused: