Question

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?).

Was it helpful?

Solution

"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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top