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

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

Post by Tom » Wed, 05 May 2004 07:23:24


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?
 
 
 

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

Post by Daniel Pra » Wed, 05 May 2004 12:07:01

Hi Tom,




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

 
 
 

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

Post by Tom » Thu, 06 May 2004 00:11:01

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?





functionality
the
 
 
 

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

Post by Daniel Pra » Thu, 06 May 2004 00:50:49

Hi Tom,



to

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
 
 
 

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

Post by Nicholas P » Thu, 06 May 2004 03:06:52

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.

--
- Nicholas Paldino [.NET/C# MVP]
- XXXX@XXXXX.COM
 
 
 

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

Post by Daniel Pra » Thu, 06 May 2004 04:23:30

Hi Nicholas,

"Nicholas Paldino [.NET/C# MVP]" < XXXX@XXXXX.COM > wrote in

(I

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
 
 
 

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

Post by Tom » Thu, 06 May 2004 07:22:37


in

menu
this
items
Edit

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.