|
How are you supposed to create merge menus using the MenuStrip control in VS2005 Beta 2? I can't successfully get MDI child forms merge with the MDI parent using the merge index, and I'm not sure if I'm just not doing it right or if it is a bug. Can someone please point me in the right direction? | | WilliamW1 Wednesday, May 18, 2005 12:12 PM | Merging with ToolStrips in significantly different than previous versions. Here are some guidelines...
In the case of an activated MDChild, we automatically merge toolstrips to the MDIParent. You need to create the source strip control that contains the items you'd like to merge into the parent. There are two aspects of the source strip - it needs to contain the items to be merged and the structure to "match" the target toolstrip. For example, in the following example, I'm trying to merge in the "Save" command.
Parent <- AllowMerge=true File Open Exit
ChildMenuStrip <-visible = false, AllowMerge=true File <- MergeAction = MatchOnly Save <- MergeAction = Insert, MergeIndex = 1;
result is Parent File Open Save Exit
Note, that File acted only to direct the Save command and was not merged. IIn addition, the toolstripitems are moved instead of being cloned like previous versions. You can also manually merge using ToolStripManager.Merge() and RevertMerge() methods in non MDI cases.
| | Erick Ellis Thursday, May 19, 2005 11:52 PM | Merging with ToolStrips in significantly different than previous versions. Here are some guidelines...
In the case of an activated MDChild, we automatically merge toolstrips to the MDIParent. You need to create the source strip control that contains the items you'd like to merge into the parent. There are two aspects of the source strip - it needs to contain the items to be merged and the structure to "match" the target toolstrip. For example, in the following example, I'm trying to merge in the "Save" command.
Parent <- AllowMerge=true File Open Exit
ChildMenuStrip <-visible = false, AllowMerge=true File <- MergeAction = MatchOnly Save <- MergeAction = Insert, MergeIndex = 1;
result is Parent File Open Save Exit
Note, that File acted only to direct the Save command and was not merged. IIn addition, the toolstripitems are moved instead of being cloned like previous versions. You can also manually merge using ToolStripManager.Merge() and RevertMerge() methods in non MDI cases.
| | Erick Ellis Thursday, May 19, 2005 11:52 PM | OK, that was very helpful and I did manage to get the menus to merge properly, thanks for that. However, there is one additional issue present, in the old one, you could set merge indexes so they were not consecutive, and it still did the same job, when you apply the same approach here, it doesn't, they must be consecutive.
Using your example:
Parent File Open <- MergeIndex = 10 Exit <- MergeIndex = 30
ChildMenuStrip File Save <- MergeIndex = 20
result is Parent File Open Exit Save
How can I get it to do it the other way? | | WilliamW1 Friday, May 20, 2005 12:14 PM | Please does anyone know? If I have to do it the way Erick Ellis suggested, that doesn't leave much flexibility if at a later stage I need to add another menu item, i.e. I need to renumber all the menu items after it and that could take ages. | | WilliamW1 Sunday, May 22, 2005 10:28 PM | I responded to your MSDN feedback request and will provide it here to see if it holds water.
Microsoft comments: I appreciate you entering the problem report. I've got a non-obvious workaround - I'd like to know if it addresses your issue and what pitfalls it may have Take the examle of File New Open >> you want custom items here, grouped Exit You could set your custom items like this: File < MatchOnly CustomN < Insert, MergeIndex 2 Custom4 < Insert, MergeIndex 2 Custom3 < Insert, MergeIndex 2 Custom2 < Insert, MergeIndex 2 Custom1 < Insert, MergeIndex 2 2 is simply the index *after* where you want your items. After merging you'd get the correct order - and this system would work for multiple child menus (they would be grouped). This would avoid having to resequence your entries (although they would be in reverse order). I hope you find this workaround adequate, because making any changes to this complex area is going to be very challenging to justify. Thanks again for the problem report and using ToolStrips! | | Erick Ellis Friday, May 27, 2005 2:43 AM | Hello Erick, I do exactily as you, but I can not get merged MDI Parente and child toolstrip!!! I'm using VB2005 with Framework.net 2.0, I need a path ?
Thanks,
DCandia | | D.Candia Thursday, April 20, 2006 1:58 PM | DCandia,
Are you using the ToolStripManager.Merge() method? As
Erick indicated, merging tool strips is different than mergine menus.
The code should look something like this:
ToolStripManager.Merge(childForm.childStrip, parentStrip.Name);
If this still isn't working, can you post the relevant code so we can take a look?
If you're looking for a paper reference, I cover MDI applications,
including merging menus as well as tool strips, in my new book (Windows
Forms in Action).
Erik
| | eebrown Saturday, April 22, 2006 2:44 AM | I would like to indicate that I am using the C# Express that was downloded from microsoft website, and I had too many confusion with regard to the menustrip merging problem. I did what Erick Ellis suggested it seams to work regardless of the merge index. However I am at the beginning.
Thanks jbattat | | jbattat Thursday, April 27, 2006 12:57 PM | Id like to add that the match only text must be "exactly" as the text your trying to match. Sounds very obvious i know but i wasted a good ten minutes trying to work out why my menus didn't merge properly. I then realised that one of my file menu items had text property as "File" while the other was "&File".
Silly oversight on my behalf i know but time is money so i hope i can save someone else a few bucks.
Cheers | | SpeakerBob Sunday, July 23, 2006 6:22 AM | Thanks for comment Iam looking into that. | | jbattat Monday, July 24, 2006 4:17 PM | | Erick Ellis wrote: | Merging with ToolStrips in significantly different than previous versions. Here are some guidelines...
In the case of an activated MDChild, we automatically merge toolstrips to theMDIParent. You need to create the source strip control that contains the items you'd like to merge into the parent. There are two aspects of the source strip - it needs to contain the items to be merged and the structure to "match" the target toolstrip. For example, in the following example, I'm trying to merge in the "Save" command.
Parent <- AllowMerge=true File Open Exit
ChildMenuStrip <-visible = false, AllowMerge=true File<-MergeAction = MatchOnly Save <- MergeAction = Insert, MergeIndex = 1;
result is Parent File Open Save Exit
Note, that File acted only to direct the Save command and was not merged. IIn addition, the toolstripitems are moved instead of being cloned like previous versions. Youcan also manually merge using ToolStripManager.Merge() and RevertMerge() methods in non MDI cases. |
|
Erick,I have a question regarding what you mentioned about the File in the ChildMenuStrip not being merged. If you need to use the DropDownOpening event for the ChildMenuStrip, what do you do? Obviously, since it doesn't get added to the Parent, the event will not get fired unless it's invoked by the File on the ChildMenuStrip. Do you have a solution to this delima? | | twang Friday, October 06, 2006 9:54 PM | You are correct that this is a dilema. Any events on the child's File menu are not active in the merged menu, so are basically lost.
The solution is to set this up somewhat artificially in the Parent's File menu. The simplest solution is to make a call from the Parent to a known child method that allows the child to take the appropriate action.
For a more elegant solution, a couple ideas for you. One option is to create an inteface that contains the methods to invoke. Child forms can then optionally support this interface. The parent can then check to see if the active child supports the interface.
IChildInterface ci = ActiveMdiChild as IChildInterface; if (ci != null) { ci.SomeMethod(param1, param2); }
Another approach, and perhaps more elegant, is to define an event in your parent form that is raised when, for example, the File menu opens. Or you could define a generic ParentDropDown event that is called for any menu open. Your child forms can then simply handle this event instead of the menu DropDown events to perform the necessary logic.
Hope that helps,
Erik | | eebrown Monday, October 09, 2006 2:07 PM | Thanks for the ideas Erik! I'll give em a shot. | | twang Monday, October 09, 2006 2:17 PM |
| Erick Ellis wrote: |
Merging with ToolStrips in significantly different than previous versions. Here are some guidelines...
In the case of an activated MDChild, we automatically merge toolstrips to theMDIParent. You need to create the source strip control that contains the items you'd like to merge into the parent. There are two aspects of the source strip - it needs to contain the items to be merged and the structure to "match" the target toolstrip. For example, in the following example, I'm trying to merge in the "Save" command.
Parent <- AllowMerge=true File Open Exit
ChildMenuStrip <-visible = false, AllowMerge=true File<-MergeAction = MatchOnly Save <- MergeAction = Insert, MergeIndex = 1;
result is Parent File Open Save Exit
Note, that File acted only to direct the Save command and was not merged. IIn addition, the toolstripitems are moved instead of being cloned like previous versions. Youcan also manually merge using ToolStripManager.Merge() and RevertMerge() methods in non MDI cases. | |
I had thought that menu merging only happened after the child form was maximized, but I was wrong. What any sense do we have two menustrips at the same time? We should merge them always. Thank you very much.
| | 成工 Saturday, November 24, 2007 3:06 AM | Thanks a lot Just what i was looking 4 | | Nicolas Rafalowski Monday, October 05, 2009 11:03 AM |
|