Can an MDI child listen for mainmenu events on the MDI parent?

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Rather than merge child menus, I would like for some common functionality
between various MDI child forms to process an event fired from the main
menu, depending on who is in focus.

Is this doable?
 
Hi Tom,

Tom said:
Rather than merge child menus, I would like for some common functionality
between various MDI child forms to process an event fired from the main
menu, depending on who is in focus.

Is this doable?

It's doable, but I think it'd be unnecessarily complicated. I would
suggest that you factor the functionality driven by the menu into one or
more interfaces. Each MDI child form can implement the interface(s). In the
menu event handler in the MDI parent, get the interface from the active
child form and call the appropriate method.

Regards,
Daniel
 
This sounds reasonable. Do you have the syntax for how I would call down to
the active MDI child form to call its interface? Would this require a
delegate?
 
Hi Tom,

Tom said:
This sounds reasonable. Do you have the syntax for how I would call down to
the active MDI child form to call its interface? Would this require a
delegate?

In the event handler in the MDI parent form "cast" the ActiveMdiChild
property of the MDI parent form to the interface. Supposing the MDI child
forms implement an interface named ISomeInterface:

...
ISomeInterface someInterface = this.ActiveMdiChild as
ISomeInterface;

if (someInterface != null)
{
someInterface.DoStuff();
}
...

Regards,
Daniel
 
Daniel and Tom,

Instead of doing this, you can place a menu on your MDI child form.
When contained within an MDI parent, the parent will merge the child menu
with the main menu and will call the child menu's event handlers as well (I
believe).

Hope this helps.
 
Hi Nicholas,

Nicholas Paldino said:
Daniel and Tom,

Instead of doing this, you can place a menu on your MDI child form.
When contained within an MDI parent, the parent will merge the child menu
with the main menu and will call the child menu's event handlers as well (I
believe).

Hope this helps.

You are 100% correct, as usual, but I will say that for our project this
wouldn't have worked as well. We have a global toolbar as well as menu items
and they are standard for every child form. I've also found it a challenge
to get the menu items to merge the way I expect (i.e. I don't want two Edit
menus, rather I want to merge the Edit menus).

Regards,
Daniel
 
Daniel Pratt said:
Hi Nicholas,

message news:%[email protected]...

You are 100% correct, as usual, but I will say that for our project this
wouldn't have worked as well. We have a global toolbar as well as menu items
and they are standard for every child form. I've also found it a challenge
to get the menu items to merge the way I expect (i.e. I don't want two Edit
menus, rather I want to merge the Edit menus).

Regards,
Daniel

I am facing the same design pattern vis-a-vis a global toolbar and agree
that your solution may be more appropriate in this scenario. I have also
found that the merge is sometimes difficult to get right.

Thanks for the tip... it appears to be exactly what I was hoping for.
 

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

Back
Top