Results 1 to 4 of 4

Thread: How to retrieve a MDIActiveChild's method?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    12

    Unhappy 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

  2. #2
    New Member Varadero's Avatar
    Join Date
    Aug 2002
    Posts
    7

    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.
    Last edited by Varadero; Aug 13th, 2002 at 02:30 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    12
    Hi Varadero, thank you for giving me a hand on my problem.. I've tried your suggestion and it works...Thanx....
    But i wondering is there another way to cater for that....
    And izzit a kind of backward/drawback of vb.net? just wondering ....

  4. #4
    New Member Varadero's Avatar
    Join Date
    Aug 2002
    Posts
    7
    There might be another way, i'm not sure about that.
    I think that doing it this way isn't too difficult.

    It might be a drawback from having the possiblity to inherit forms and stuff. With inheritance you can now create a base form from which you create all your other forms. This way you have all the functions and subs (only the PUBLIC ones) that you created on your base form.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width