MenuStrip -- Mdi merge

J

John J. Hughes II

Could someone explain how to merge the form menu with the mdi container
window. The menu strip items on the form window merge but I either end up
with a blank blue menu on the form or top list of items that don't do
anything.

MDI Container.IsMdiContainer = true

MenuStrip.AllowMerge = true
/// First menu items
this.miFile.MergeAction = System.Windows.Forms.MergeAction.Insert;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

/// On the sub form
this.miFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[]
{
this.toolStripSeparator1,
this.miClose});
this.miFile.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

Regards,
John
 
S

Steve Barnett

I struggled with this for ages and eventually, by trial and error, got it
working. Best to show where I got to with an illustration of the MergeAction
and MergeIndex values

MDI parent form has a "File" menu with the generally available options:

Item Merge Action Merge Index
File Append 1
New Append 2
Open Append 2
Print Setup Append 25
Exit Append 99

All of these items are handled by methods on the MDI parent form.

The MDI child form also has a file menu, with options specific to a child
form:

Item Merge Action Merge Index
File MatchOnly -1
Close Insert 2 (Inserts
Close after item 2)
---- Insert 3 (separator
bar)
Save Insert 4
Save-as Insert 5
----- Insert 6
Print Insert 7
Print Preview Insert 8

All of these menu items are handled by methods on the mdi child form. When a
child form is opened, the entire child menu gets merged between the "open"
and "Print setup" items of the parent menu.

Next job was to insert an "edit" menu after the "file" menu. Since there is
no such menu on the parent form, I needed to add a new one from the child
form. On the child, I defined:

Item Merge Action Merge Index
Edit Insert 2
Undo Append -1
< rest of the options are the same >

In this case, because the Edit menu is a top level menu, it gets inserted
after top level item "1", which is the "file" menu from the parent form.
Because there is no merging of lower level items, I can append them all in
the child form.

Hope some of that makes sense. I have no idea whether it's the "right" thing
to do because the documentation and examples are non-existent. However, it
works.

You'll also be pleased to know that, when you come to merge toolbars, the
rules change completely!

HTH
Steve





John J. Hughes II said:
Could someone explain how to merge the form menu with the mdi container
window. The menu strip items on the form window merge but I either end up
with a blank blue menu on the form or top list of items that don't do
anything.

MDI Container.IsMdiContainer = true

MenuStrip.AllowMerge = true
/// First menu items
this.miFile.MergeAction = System.Windows.Forms.MergeAction.Insert;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

/// On the sub form
this.miFile.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.toolStripSeparator1,
this.miClose});
this.miFile.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

Regards,
John
 
J

John J. Hughes II

Steve,

First thanks for the detailed response.

I sort of fixed the problem by setting the child form's menu strip visible
property to false.

I change my menus based on your suggestion. Mainly changed the parent menu
upper items to "Append" with the location index being correct for where I
want them. Then I changed the child form menu items parents to -1 / match
only. I can only assume they are using the name to match with so I made
sure the name are the same.

All the sub items are merging correctly on the parent menu but the child
form still has a menu strip with a list of parent items that does nothing.
Oh well as I said I changed the child menu form's menu strip visible
property to false and the problem seems to be solved.

And yes I agree a good sample would be nice from MS. The compression sample
the BOL leads you too is beyond useless.

Don't you just love guessing games?

Regards,
John

Steve Barnett said:
I struggled with this for ages and eventually, by trial and error, got it
working. Best to show where I got to with an illustration of the
MergeAction and MergeIndex values

MDI parent form has a "File" menu with the generally available options:

Item Merge Action Merge Index
File Append 1
New Append 2
Open Append 2
Print Setup Append 25
Exit Append 99

All of these items are handled by methods on the MDI parent form.

The MDI child form also has a file menu, with options specific to a child
form:

Item Merge Action Merge Index
File MatchOnly -1
Close Insert 2 (Inserts
Close after item 2)
---- Insert 3 (separator
bar)
Save Insert 4
Save-as Insert 5
----- Insert 6
Print Insert 7
Print Preview Insert 8

All of these menu items are handled by methods on the mdi child form. When
a child form is opened, the entire child menu gets merged between the
"open" and "Print setup" items of the parent menu.

Next job was to insert an "edit" menu after the "file" menu. Since there
is no such menu on the parent form, I needed to add a new one from the
child form. On the child, I defined:

Item Merge Action Merge Index
Edit Insert 2
Undo Append -1
< rest of the options are the same >

In this case, because the Edit menu is a top level menu, it gets inserted
after top level item "1", which is the "file" menu from the parent form.
Because there is no merging of lower level items, I can append them all in
the child form.

Hope some of that makes sense. I have no idea whether it's the "right"
thing to do because the documentation and examples are non-existent.
However, it works.

You'll also be pleased to know that, when you come to merge toolbars, the
rules change completely!

HTH
Steve





John J. Hughes II said:
Could someone explain how to merge the form menu with the mdi container
window. The menu strip items on the form window merge but I either end
up with a blank blue menu on the form or top list of items that don't do
anything.

MDI Container.IsMdiContainer = true

MenuStrip.AllowMerge = true
/// First menu items
this.miFile.MergeAction = System.Windows.Forms.MergeAction.Insert;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

/// On the sub form
this.miFile.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.toolStripSeparator1,
this.miClose});
this.miFile.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

Regards,
John
 
S

Steve Barnett

Sorry, yes, you're right - I didn't say to hide the menu strip on the child
form. I am doing that too.

The items that are appropriate for the parent form are handled by the parent
form... that's where I put their handlers. This for the child are handled by
the child because that's where I put their handlers. I have no "duplicate"
items on both forms though... you seem to imply you do.

You'll have far more fun when you get to merge tool bars - they merged
automatically in the Beta version of VC# Express and then stopped merging
automatically in the final release. I now have to merge them my self with
some very unintuitive code.

At some stage, I may strip out the more advanced stuff I put in to my editor
and upload it as an example to CodeProject... either that or I'll have
Christmas off!

All the best
Steve


John J. Hughes II said:
Steve,

First thanks for the detailed response.

I sort of fixed the problem by setting the child form's menu strip visible
property to false.

I change my menus based on your suggestion. Mainly changed the parent
menu upper items to "Append" with the location index being correct for
where I want them. Then I changed the child form menu items parents to -1
/ match only. I can only assume they are using the name to match with so
I made sure the name are the same.

All the sub items are merging correctly on the parent menu but the child
form still has a menu strip with a list of parent items that does nothing.
Oh well as I said I changed the child menu form's menu strip visible
property to false and the problem seems to be solved.

And yes I agree a good sample would be nice from MS. The compression
sample the BOL leads you too is beyond useless.

Don't you just love guessing games?

Regards,
John

Steve Barnett said:
I struggled with this for ages and eventually, by trial and error, got it
working. Best to show where I got to with an illustration of the
MergeAction and MergeIndex values

MDI parent form has a "File" menu with the generally available options:

Item Merge Action Merge Index
File Append 1
New Append 2
Open Append 2
Print Setup Append 25
Exit Append 99

All of these items are handled by methods on the MDI parent form.

The MDI child form also has a file menu, with options specific to a child
form:

Item Merge Action Merge Index
File MatchOnly -1
Close Insert 2 (Inserts
Close after item 2)
---- Insert 3
(separator bar)
Save Insert 4
Save-as Insert 5
----- Insert 6
Print Insert 7
Print Preview Insert 8

All of these menu items are handled by methods on the mdi child form.
When a child form is opened, the entire child menu gets merged between
the "open" and "Print setup" items of the parent menu.

Next job was to insert an "edit" menu after the "file" menu. Since there
is no such menu on the parent form, I needed to add a new one from the
child form. On the child, I defined:

Item Merge Action Merge Index
Edit Insert 2
Undo Append -1
< rest of the options are the same >

In this case, because the Edit menu is a top level menu, it gets inserted
after top level item "1", which is the "file" menu from the parent form.
Because there is no merging of lower level items, I can append them all
in the child form.

Hope some of that makes sense. I have no idea whether it's the "right"
thing to do because the documentation and examples are non-existent.
However, it works.

You'll also be pleased to know that, when you come to merge toolbars, the
rules change completely!

HTH
Steve





John J. Hughes II said:
Could someone explain how to merge the form menu with the mdi container
window. The menu strip items on the form window merge but I either end
up with a blank blue menu on the form or top list of items that don't do
anything.

MDI Container.IsMdiContainer = true

MenuStrip.AllowMerge = true
/// First menu items
this.miFile.MergeAction = System.Windows.Forms.MergeAction.Insert;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

/// On the sub form
this.miFile.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.toolStripSeparator1,
this.miClose});
this.miFile.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

Regards,
John
 
J

John J. Hughes II

Yea it was the visable thing that was throwing me. Very not obvious!

Just the parent items are common form the form to the parent. It was just
having the parent item on both the form and the container was a bit
confusing and ugly.

I don't think I will do the toolbar thing. I don't have much of a problem
on the few windows I have that use them just being on the form itself.

Thanks again for the help.

Regards,
John

Steve Barnett said:
Sorry, yes, you're right - I didn't say to hide the menu strip on the
child form. I am doing that too.

The items that are appropriate for the parent form are handled by the
parent form... that's where I put their handlers. This for the child are
handled by the child because that's where I put their handlers. I have no
"duplicate" items on both forms though... you seem to imply you do.

You'll have far more fun when you get to merge tool bars - they merged
automatically in the Beta version of VC# Express and then stopped merging
automatically in the final release. I now have to merge them my self with
some very unintuitive code.

At some stage, I may strip out the more advanced stuff I put in to my
editor and upload it as an example to CodeProject... either that or I'll
have Christmas off!

All the best
Steve


John J. Hughes II said:
Steve,

First thanks for the detailed response.

I sort of fixed the problem by setting the child form's menu strip
visible property to false.

I change my menus based on your suggestion. Mainly changed the parent
menu upper items to "Append" with the location index being correct for
where I want them. Then I changed the child form menu items parents
to -1 / match only. I can only assume they are using the name to match
with so I made sure the name are the same.

All the sub items are merging correctly on the parent menu but the child
form still has a menu strip with a list of parent items that does
nothing. Oh well as I said I changed the child menu form's menu strip
visible property to false and the problem seems to be solved.

And yes I agree a good sample would be nice from MS. The compression
sample the BOL leads you too is beyond useless.

Don't you just love guessing games?

Regards,
John

Steve Barnett said:
I struggled with this for ages and eventually, by trial and error, got it
working. Best to show where I got to with an illustration of the
MergeAction and MergeIndex values

MDI parent form has a "File" menu with the generally available options:

Item Merge Action Merge Index
File Append 1
New Append 2
Open Append 2
Print Setup Append 25
Exit Append 99

All of these items are handled by methods on the MDI parent form.

The MDI child form also has a file menu, with options specific to a
child form:

Item Merge Action Merge Index
File MatchOnly -1
Close Insert 2 (Inserts
Close after item 2)
---- Insert 3 (separator bar)
Save Insert 4
Save-as Insert 5
----- Insert 6
Print Insert 7
Print Preview Insert 8

All of these menu items are handled by methods on the mdi child form.
When a child form is opened, the entire child menu gets merged between
the "open" and "Print setup" items of the parent menu.

Next job was to insert an "edit" menu after the "file" menu. Since there
is no such menu on the parent form, I needed to add a new one from the
child form. On the child, I defined:

Item Merge Action Merge Index
Edit Insert 2
Undo Append -1
< rest of the options are the same >

In this case, because the Edit menu is a top level menu, it gets
inserted after top level item "1", which is the "file" menu from the
parent form. Because there is no merging of lower level items, I can
append them all in the child form.

Hope some of that makes sense. I have no idea whether it's the "right"
thing to do because the documentation and examples are non-existent.
However, it works.

You'll also be pleased to know that, when you come to merge toolbars,
the rules change completely!

HTH
Steve





Could someone explain how to merge the form menu with the mdi container
window. The menu strip items on the form window merge but I either end
up with a blank blue menu on the form or top list of items that don't
do anything.

MDI Container.IsMdiContainer = true

MenuStrip.AllowMerge = true
/// First menu items
this.miFile.MergeAction = System.Windows.Forms.MergeAction.Insert;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

/// On the sub form
this.miFile.DropDownItems.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.toolStripSeparator1,
this.miClose});
this.miFile.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
this.miFile.MergeIndex = 1;
this.miFile.Name = "miFile";
this.miFile.Size = new System.Drawing.Size(35, 20);
this.miFile.Text = "&File";

Regards,
John
 

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