Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI Children with Menus

Status
Not open for further replies.

Tarwn

Programmer
Mar 20, 2001
5,787
US
Ok, so here I am playing with MDI Children in a form and I just noticed that now that they are children their MainMenu's seem to disappear. I've tried some google searches (I apparently have several languages that haven't been installed, as most of the hits were not in English) and tried searching this forum, but didn't get anything useful.

Here's the situation:
A form (we will call it Form1 in good MS fashion) that is an MDI Container. It has a MainMenu (which btw doesn't respond consistently to mnemonics I added, but thats another issue)
A second form (we'll call it Form2) that has a MainMenu and a various set of controls.

I open Form2 from Form1 like so:
Code:
   Dim f as New Form2()
   f.MdiParent = Me
   f.Show()
Now that I have a Form2 object open as an MDI Child it is interesting to note that the MainMenu for Form2 is not being displayed.

Ok, to test that it is definately an MDI problem, we comment out the MDI line:
Code:
   Dim f as New Form2()
   'f.MdiParent = Me
   f.Show()

Hmm, now we have a MainMenu on our Form2 object...?

If anyone knows a way around this or an explanation for why this occurs as it does I'd appreciate it.
(My guess is that this might be a sloppy way to keep menu key event handling simple, ie so that a Ctrl+? mnemonic can be checke against only one menu. If so it's sloppy, as all it would need to do is check the screen in focus then check it's parents in a recursive fashion)

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Gahhh...I just found my menu. For people who don't want to try it themselves here is what happens:

The MenuItem's from the MainMenu in the child merge with the MainMenu in the parent...it wasn't instantly obvious to me because it was about the last thing I would expect to happen.

The question still remains, is it possible to have a MainMenu in the child (and have it displayed in the child), but now I'm adding another question, anyone know why they would choose to merge the childs menus with the parent???

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
I have yet to find a solution for this, so I am open to opinions and such. This seems like a strange way for things to work. I'm looking into replacing the inner main menu with a toolbar, but I am still curious about the initial problem even if it won't be applicable to this current project i am working on. If anyone has any thoughts, please feel free to post...

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Try this:

Code:
Dim f2 As New Form2()
Dim mi As MenuItem
f2.MdiParent = Me
For Each mi In MainMenu1.MenuItems
     mi.MergeType = MenuMerge.Remove
Next
f2.Show()
 
I can't recall ever seeing a windows application with main menus -> form w/ main menus.
 
RiverGuy: Thanks, I'll give that a shot. Unfortunatly I'm moving over the next couple days, but I'll post/star back when I get a chance to try it.

Baddos: I know, but I have the choice between using a menu or having 50 million buttons in the form. I need the options to be intuitively connected to the child form (otherwise they are next to meaningless from view of main form) but at the same time want to save real estate and confusion levels by compacting them into a menu. A MainMenu seemed more intuitive for these options than a context menu, so I was trying to do that. I tried a toolbar and it just wouldn't work right, either everything fit nd you had to depend on the tooltip tofigure out what each was, or the toolbar started stealing real estate and lookng ugly.

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Tarwn,

Did you every figure out the mnemonics issue. I know that this was a side note, but I have the same thing happening(I think). What I have noticed is that on the initial load the mnemonics don't work on form1, they also don't work on form2, however once you close form2 and return to form one the mnemonics seem to work fine.

Any information you found would be helpfull.

FYI I also have an mdi app with several forms and sub menus.
 
I think it has to do with how they handle focus shifting between parent and child forms. This whole MDI impolementation seems kind of forced, in that I have run into several problems with it tryiung to treat parent and child forms as seperate forms altogether.

My guess is that when the chikld form opens it steals the focus and the parent does not get it back until it has no children.

This is based on the same wierd stuff happening with mnemonics on mine, which was a little while ago. I think my solution in the end was to get rid of the mnemonics. basically I decided if I couldn't provide them to the user all the time, I couldn't advertise them/ie use them in the main menu.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Thanks for the super quick response.

I was actually thinking about doing the same thing with removing the mnemonics. I was just hopeing that somebody else had seen and solved the same problems.

I will play with the focus idea for a while and let you know if that will take care of it.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top