1

I am developing a MDI application in c#. I am having trouble when two MenuStrip are combined:

I have the parent Parent Form with its MenuStrip parentMenu and some ToolStripMenuItem elements: Option1, Option2.

Then I have a child Form with its MenuStrip parentMenu and two ToolStripMenuItem elements: Option1 and OtherOption. The merging propierties of these are match-only for Opcion1and append for OtherOption

Now, here is the problem: When the child form is showed and the two MenuStripare combined, the event parentMenu.ItemAdded is tiggrered because OtherOptionis added to the parentMenu.Items collection. This is not the case for Option1. Notice that there may be some elements in Option1.DropDownItems(in the child form) that are not present in the Option1.DropDownItems in the parent form.

How can I get notified about these items that being added?

(Just for clarity: Suppose that parentMenu.Items only contains a ToolStripMenuItem Option1 which only contains a ToolStripMenuItem, say 'optionA'. Suppose that childMenu.Items only contains a ToolStripMenuItem Option1 which only contains ToolStripMenuItem optionB. When the two menus merge, how can I get notified about the item optionB being added the the father? Or how can I get notified about two menus merging, knowing which elements are new?).

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
José D.
  • 4,175
  • 7
  • 28
  • 47

1 Answers1

0

"MenuStrip merging moves menu items from one ToolStrip to another rather than cloning them, as was the case with MainMenu." See here.

Because it is moving them rather than cloning them, try the OwnerChanged event on the ToolStripItem. Hook up to this event for each of your items and it will notify you when it is moved to another toolstrip.

richard
  • 12,263
  • 23
  • 95
  • 151
  • Can the OnwerChanged event be tiggered if no merge is done (for any other reason) ? – José D. Nov 17 '13 at 19:21
  • Yes. If the owner changes, the event will fire. For example you could move it around manually. But this is not a problem because you can just look at the new owner and determine if it was merged or not (i.e. if the owner is the mdiparent's menustrip, you know it was merged). – richard Nov 17 '13 at 19:23
  • Still feels like not the right way to do it. I'll mark it as valid if it is the only way – José D. Nov 17 '13 at 19:26
  • 1
    I know what you want...you want a MenuMerged event that would give you the list of items that were merged. Unfortunately it doesn't exist. I think the way I mentioned is the simplest way to get the effect you are looking for. – richard Nov 17 '13 at 19:48
  • I though it auto assigned when marking answer as valid. There you go – José D. Nov 24 '13 at 02:22