Dynamically altering a MDI Container form's MainMenu according to the number of MdiChildren

  • Thread starter Thread starter Mark Rae
  • Start date Start date
M

Mark Rae

Hi,

I have a very simple MDI application where the MDI Container form has an
even simpler MainMenu. I want to disable a couple of the menu items if there
are no MdiChild windows open.

I had thought that a good way to do this would be to place code behind the
Load and Closed events of the child form to interrogate the

this.MdiParent.MdiChildren.Length

property. However, although this returns the correct value in the Load
event, it doesn't in the Closed event. According to the docs, a form's
Closed event fires *after* the form has closed, e.g., even if I close the
last child form, the MdiChildren.Length property of the MDI Container form
still gives me a value of 1.

Is there a better way of doing this?

Any assistance gratefully received.

Best regards,

Mark Rae
 
Hi Mark.

I think this is what you're talking about.

You need two menus, one for the container and one for the child.
Lets say I want to merge the "&File" section of the two, set the "File's" MergeType to MenuMerge::MergeItems, for both menus.
Next you need to set the MergeOrder of each subitem, this is an int, 0 being highest. So "&New" on the parent could be 0, the "&Save" on the child could be 1, and finally the "Seperator" and "E&xit" could be 2.
 
I thought I was in the C++ section, the enum "MenuMerge::MergeItems" should read "MenuMerge.MergeItems"
 
That doesn't enable and disable the menu items - when the last child form is
closed, its menu items are removed from the MDI Container's menu, which
isn't what I want.

I figured it out - thanks for the reply.

Vas said:
Hi Mark.

I think this is what you're talking about.

You need two menus, one for the container and one for the child.
Lets say I want to merge the "&File" section of the two, set the "File's"
MergeType to MenuMerge::MergeItems, for both menus.
Next you need to set the MergeOrder of each subitem, this is an int, 0
being highest. So "&New" on the parent could be 0, the "&Save" on the child
could be 1, and finally the "Seperator" and "E&xit" could be 2.
 
Back
Top