How to retrieve a MDIActiveChild's method?
Hi,
I faced a problem where i need to retrieve a MDIActiveChild's method when a i take an action on the MDI Parent form .
Example:
Method in the MDI child form "FrmChild"
Public sub SayMyFormName()
msgbox ("FrmChild")
End sub
Action on MDI Parent
Private Sub ToolBar1_ButtonClick......
'I can't declare frmActive as FrmChild because they are
' many forms here and all the forms here contain a sub
'name SayMyFormName()
Dim frmActive As Form = Me.ActiveMdiChild
'so i'll get error when i try get the method from child form
'but it stil generate correct msgbox when run the
'application by ignore the error prompted
'Error occur becoz the Form class does not have the
' SayMyFormName sub procedure
frmActive.SayMyFormName()
end sub
So..Anybody outhere can give me a hand on this? How do i retrieve the active child method from the MDI parent action without explicitly declare the frmActive as currenrform class.
Thanx in advance
RE: How to retrieve a MDIActiveChild's method?
I tried the following and it seemed to work just fine.
I created an MDIParent form (Form1).
I then created a bas form (Form2) which contained the sub SayMyFormName.
After that I created an inherited form (Form3) which was inherited from Form2. So i got the SayMyFormName inherited from the Form2.
Action on MDI Parent
Private Sub mnuTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuTest.Click
Dim lForm As Form2 (=> the base form which contains the sub)
lForm = ActiveMdiChild
lForm.SayMyFormName()
End Sub
This seemed to do the trick.
So now you can simply inherit all the other forms from that base-form (Form2) and they all have the method "SayMyFormName".
you have to remember to make the "SayMyFormName" Overridable, then on the Inherited form (Form3) you need to override this sub.
So on Form2 it will look like this :
Public Overridable Sub SayMyFormName
MsgBox(me.name)
End Sub
And on Form3 it will look like this :
Public Overrides Sub SayHello()
MsgBox(Me.Name)
End Sub
If you want the code for my example, just let me know.