Called A Function in Array Of MDI Child Forms

  • Thread starter Thread starter Daniel Friend
  • Start date Start date
D

Daniel Friend

I have a bunch of mdi child forms and I use a collection for which forms are
opened. I would like to call a public function in the open forms called
ChangeFormat, but I am getting the following error:

'ChangeFormat' is not a member of 'System.Windows.Forms.Form'.

Can somebody tell me how I can achieve this?

Thanks,

Dan

Example Code:
----------------------------------------------------------------------

Public Sub ChangeFormat()
Try
Dim frmAny As Form
For Each frmAny In Forms
Try
frmAny.ChangeFormat()
Catch
End Try
Next
Catch ex As Exception
End Try
End Sub
 
* "Daniel Friend said:
I have a bunch of mdi child forms and I use a collection for which forms are
opened. I would like to call a public function in the open forms called
ChangeFormat, but I am getting the following error:

'ChangeFormat' is not a member of 'System.Windows.Forms.Form'.
[...]
Public Sub ChangeFormat()
Try
Dim frmAny As Form
For Each frmAny In Forms
Try
frmAny.ChangeFormat()

Replace the line above with this:

\\\
DirectCast(frmAny, AnyForm).ChangeFormat()
///

'AnyForm' is the type of your MDI children.
 
What if there are about 50 types of MDI children and you don't know which
one for need to change? I tried the following code to get the type, but I
get an error:
"aType is not defined"

Thanks for your help,

Dan

Public Sub ChangeFormat()
Try
Dim frmAny As Form
For Each frmAny In Forms
Dim aType As Type
aType = frmAny.GetType
Try
DirectCast(frmAny, aType).GetTheme()
Catch ex As Exception
End Try
Next
End Try
End Sub


Herfried K. Wagner said:
* "Daniel Friend said:
I have a bunch of mdi child forms and I use a collection for which forms are
opened. I would like to call a public function in the open forms called
ChangeFormat, but I am getting the following error:

'ChangeFormat' is not a member of 'System.Windows.Forms.Form'.
[...]
Public Sub ChangeFormat()
Try
Dim frmAny As Form
For Each frmAny In Forms
Try
frmAny.ChangeFormat()

Replace the line above with this:

\\\
DirectCast(frmAny, AnyForm).ChangeFormat()
///

'AnyForm' is the type of your MDI children.
 
* "Daniel Friend said:
What if there are about 50 types of MDI children and you don't know which
one for need to change? I tried the following code to get the type, but I
get an error:
"aType is not defined"

Create an interface that all MDI child classes implement:

\\\
Public Interface ITheme
Sub GetTheme()
End Property
///

\\\
Public Class Form2
Inherits System.Windows.Forms.Form
Implements ITheme

Public Sub GetTheme() Implements ITheme.GetTheme
...
End Sub
 
Back
Top