bug: active MDI child window does not show the menu

A

Aurora

I have a MDI application in which the active MDI child window does not show
the menu. All the other children display nicely their menu. As soon as the
active child windows loses the focus its menus shows up. Parent and child
share the same stripmenu.
Could you help ?
Aurora
 
M

Martin H.

Hello Aurora,

I think the problem is that you use the same stripmenu.
What happens is that you make a reference from the MDIparent to the
child, right? It seems that each object can only be shown once at the
same time. What you would have to do IF you say that the children need
to have identical menus is that you make an identical copy of the MDI menu.

But pardon me asking: One feature of MDI is that the children share the
menu with the MDI parent - only the parent has the menu and if you want
to use a specific action on a child menu, then you just need to select
the menu in the parent.

If you want to have identical menus in the MDI children I suggest that
you create the menu the child window. If all children are identical then
it is very easy as you just need to create another instance of that form.


' This code was generated from VB 2008 (I just stripped the German
' comments.
Dim ChildForm As New Form1
ChildForm.MdiParent = Me

m_ChildFormNumber += 1
ChildForm.Text = "Window " & m_ChildFormNumber

ChildForm.Show()

' End of Code

I hope that helps.

Best regards,

Martin
 
A

Aurora

Inappropriate said that the parent and the child share the same stripmenu
because there 2 different forms i.e 2 different classes which means the
menus belongs to each form.
I have renamed the stripmenu in the child form and still I get the mentioned
bug.
The problem is the menu is not displayed ONLY for the active child , but for
all other child forms and parent.
Toggling focus between two child forms , the one having the focus loses the
menu :((

Aurora
 
M

Martin H.

Hello Aurora,

the idea of MDI is that all windows share the same menu (which is useful
for example for a text editor that supports editing several files at the
same time). So the menu is only created once - on the MDI parent and all
MDI children use the same menu. If your MDI children are more or less
identical, you could identify them with the method described below. If
this is not possible, you might either make them no MDI children (so
they can have their own menu) or maybe use a toolstrip (and mimic a menu
with ToolStripSplitButtons).


To identify which form is active, you could do something like this:

In your MDI form (or as a global variable in a module):
Public frmActiveForm As Form = Nothing

In your MDIchildren:
(Let's say in the Activated event).
Dim frmMDIparent As MDIParent1 = CType(Me.MdiParent, MDIParent1)
frmMDIparent.frmActiveForm = Me

This way you can clearly identify which form is active. So you can use
that info in your MDI form's menu subs.

Hope this helps.

Beste wishes,

Martin
 
M

Martin H.

Hello Aurora,

I just had a look again and DOH!

The menu shows up, but the behavior is different from ClassicVB.

In ClassicVB the child's menu replaces the MDI's menu.
In VB.NET the child's menu is ADDED to the MDI's menu, so you find it at
the right hand end of it. So either you create an empty menu for the MDI
form your you hide the MDI's menus.

Best wishes,

Martin
 
A

Aurora

Yes, this is the problem. I have fixed it seting the MergeAction for child
menu items to MergeAction.Insert
Now the child has its own menu and ir is not appened to the parent form
anymore.

Aurora
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top