Calling sub in MDI child forms

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

Hi,

Can someone please help.

I wish to loop through all my MDI children and call a sub procedure I have
created, my problem is that the sub procedure may not exist in all the MDI
children so the program crashes.

What is the best way to tackle this.

Thanks.

Merlin
 
In your loop you should check the type of each form. If the types matches
the type of your "special" form, then you can use the method:

For Each form As Form In Me.MdiChildren
If form.GetType Is GetType(Form1) Then
CType(form, Form1).MyMethod()
End If
Next


--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
* "Merlin said:
I wish to loop through all my MDI children and call a sub procedure I have
created, my problem is that the sub procedure may not exist in all the MDI
children so the program crashes.

\\\
Dim f As Form
For Each f In Me.MdiChildren
If TypeOf f Is MyChildForm1 Then
DirectCast(f, MyChildForm1).MyMethod()
End If
Next f
///
 
As an alternative to looping through each form with an If...Then you could
create a class whose purpose is to raise application wide events and expose
it as a property of a module.

Then each MDI Child that should respond to a given event could subscribe to
that class and react to the event.



--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
 
Back
Top