parent / child form w/ menu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Darin

    parent / child form w/ menu

    I have a parent form that has a menu. I then have a child form on the
    menu. From the child form I need to change the parent form's menu - how
    can i do that? I tried me.parent.mfavo rites, but that doesn't exist (the
    menu name is mfavorites).

    Thanks.

    Darin

    *** Sent via Developersdex http://www.developersdex.com ***
  • Armin Zingler

    #2
    Re: parent / child form w/ menu

    "Darin" <darin_nospam@n ospameverschrie b
    I have a parent form that has a menu. I then have a child form on
    the menu. From the child form I need to change the parent form's
    menu - how can i do that? I tried me.parent.mfavo rites, but that
    doesn't exist (the menu name is mfavorites).
    Yes, it doesn't exist because every Form can be the parent of the child
    form. Not every parent has that property. If you know that the parent is
    always of type ParentForm, you can cast to that type (use DirectCast). If
    you want to write reusable code, depending on the situation, I'd probably
    raise an event in the child form, caught by the parent form.


    Armin

    Comment

    • Darin

      #3
      Re: parent / child form w/ menu

      Well, i don't quite understand the direct cast, so let's look at the
      raiseevent.

      My parent form is in an EXE that is a stand alone - the child is in a
      DLL, so the two forms (fUTStart in EXE and fUTMenu in DLL) can't
      actually see each other.

      Not sure how i can raise an event on the parent form w/o the two forms
      really "knowing" about each other.

      Darin

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • Jack Jackson

        #4
        Re: parent / child form w/ menu

        On Wed, 25 Jun 2008 12:04:02 -0700, Darin <darin_nospam@n ospamever>
        wrote:
        >Well, i don't quite understand the direct cast, so let's look at the
        >raiseevent.
        If the parent form is an instance of class MyParentForm:
        Dim myParent as MyParentForm = DirectCast(me.P arent, MyParentForm)
        myParent.mfavor ites. ...
        This requires that the child form project have a reference to the main
        form project.
        >
        >My parent form is in an EXE that is a stand alone - the child is in a
        >DLL, so the two forms (fUTStart in EXE and fUTMenu in DLL) can't
        >actually see each other.
        Just because the class definitions of two forms are in different
        assemblies doesn't mean they can't 'see' each other, whatever you mean
        by 'see'. If either assembly has a reference to the other, then you
        can reference from one to the other.
        >Not sure how i can raise an event on the parent form w/o the two forms
        >really "knowing" about each other.
        You can't. The child project would need a reference to the parent
        form project so it could raise the parent form's event.

        Or you could define an Interface in a common assembly and have the
        parent form Implement that interface, then both parent and child
        projects would need to reference the project that defines the
        Interface.

        Comment

        • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

          #5
          Re: parent / child form w/ menu

          Jack,

          No, the child form would raise an event and the parent form would handle the
          event.

          Using this technique the child form can be reused with any parent form,
          since the child form does not need to know anything about the parent form.

          Kerry Moorman


          "Jack Jackson" wrote:
          >
          You can't. The child project would need a reference to the parent
          form project so it could raise the parent form's event.
          >

          Comment

          • Darin

            #6
            Re: parent / child form w/ menu

            how does the child form raise an event on the parent form?


            Darin

            *** Sent via Developersdex http://www.developersdex.com ***

            Comment

            • Armin Zingler

              #7
              Re: parent / child form w/ menu

              "Darin" <darin_nospam@n ospameverschrie b
              Well, i don't quite understand the direct cast, so let's look at the
              raiseevent.
              >
              My parent form is in an EXE that is a stand alone - the child is in
              a DLL, so the two forms (fUTStart in EXE and fUTMenu in DLL) can't
              actually see each other.
              >
              Not sure how i can raise an event on the parent form w/o the two
              forms really "knowing" about each other.
              The parent Form knows the child Form, therefore it can handle the child's
              events.


              Armin

              Comment

              • Jack Jackson

                #8
                Re: parent / child form w/ menu

                It doesn't. As Kerry pointed out, the child raises an event that it
                defines. The parent subscribes to the child's event with AddHandler.

                On Wed, 25 Jun 2008 14:46:55 -0700, Darin <darin_nospam@n ospamever>
                wrote:
                >how does the child form raise an event on the parent form?
                >
                >
                >Darin
                >
                >*** Sent via Developersdex http://www.developersdex.com ***

                Comment

                Working...