How can execute the public method inside the MDIparent from the client form?

Experts,

I have an MDI form and child form. MDI form has two public methods which should be called or executed from the child form.

Please guide me with same sample pages or code pages with c# or c++ visual studio 2003 version.

Thanks,




Answer this question

How can execute the public method inside the MDIparent from the client form?

  • B. Wesley

    I find some information in this pages, same as what I need, but could not clearly understand the solution. Is there any C# example for this Any help

    Thanks

    ========
    I have a main form (an mdi container) with a menu and the item "open".
    When clicking "open" a child form appears. Now, i don't want that
    several childforms are opened. So i want the "open" item to be
    disabled when this child form is shown. When i close this child form
    i want the "open" item in the menu to be enabled again so that i can
    open the child form whenever i want. How can i do this Anyone an
    idea
    =========

    ========================
    http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/99d82bc37ea2dd51/fc927daff26f1e84#fc927daff26f1e84

    directcast(sender, menuitem).enabled = false
    > After creating the instance of the child

    private m_Child as form2 'at class level (= field of the class)
    '...
    m_child = new form2
    > within the MDI container, use the Addhandler statement to handle the
    closed
    > event of the child.

    addhandler m_child.closed, addressof ChildClosed
    > In the event handler, enable the menuitem.

    ...and remove the handler:

    private sub ChildClosed( _
    ByVal sender As Object, ByVal e As System.EventArgs)

    menuitemx.enabled = true
    removehandler m_child.closed, addressof ChildClosed
    m_child = nothing
    end sub

    ========================


  • jalal khodabandeh

    Chris Vega,

    Great resource to me, and very helpful,

    Thanks a lot,



  • AParker

    Basically, the idea is to cast the MDIParent property of your MDIChild form to the type of your MDIForm, something like this:



    MyMDIForm mdiform = ((MyMDIForm)this.MdiParent);



    And then access your two public methods from the casted reference variable:



    mdiform.MyPublicMethod1();
    mdiform.MyPublicMethod2();



    Regards,

    -chris

  • How can execute the public method inside the MDIparent from the client form?