parent / child form w/ menu

D

Darin

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.mfavorites, but that doesn't exist (the
menu name is mfavorites).

Thanks.

Darin
 
A

Armin Zingler

Darin said:
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.mfavorites, 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
 
D

Darin

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
 
A

Armin Zingler

Darin said:
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
 
J

Jack Jackson

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.Parent, MyParentForm)
myParent.mfavorites. ...
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.
 
K

Kerry Moorman

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
 
J

Jack Jackson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top