Problems with Merging MDI Menu.

Troy

Well-known member
Joined
Feb 7, 2005
Messages
153
Programming Experience
10+
Ok I'm going crazy here. I have tried setting up a menu on my parent form.

Lets just use one field for example.

I Name my Menu Item File

on my Parent form I have File <-- Name is MenuFile
then we have under file New <--- Name is FileNew

I set File's MergeAction to Insert

I set New's MergeIndex as 0

Now I goto the child form

I create File and name it MenuFile
I create under it Open and name it FileOpen

I set the MergeAction on File to Insert
I set the MergeAction on Open to Insert
I set the MergeIndex of Open to 1

I run the program

After the child is displayed it show 2 File menu's in the menubar

one for the parent and one for the child still

I have tried several combinations and nothing is getting it to merge.


HELP!:eek:
 
YAY! Thankyou very very much I wasn't setting the File Menu to Match Only on both menu's That made the difference. Now I understand how to do this. Every example I had was for previous to 2005 and referred to Merge Type and Merge Order. These are not in 2005 but I found Merge Action and Figured it was the same as Merge Type and Merge Index was the same as Merge Order. The examples though said to set the File Menu's as MergeItems which I figured was Insert in 2005 but turns out you need to set them to MatchOnly so the second doesn't get added, which makes sense.

Long Story Short thankyou very much it fixed my confusion.;)
 
Sorry to say now I'm having problems merging my toolstrip.toolbar items.

I've tried setting the MDI forms Items to MergeType = Append

and the Child forms items to MergeType = Insert and still won't bounce

them over. can you give me an example using the toolstrip control?
 
Here is example code that merges mdiChild toolstrip1 into mdiParent toolstrip1:
VB.NET:
Private Sub MDIParent1_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.MdiChildActivate
  ToolStripManager.Merge(Me.ActiveMdiChild.Controls("ToolStrip1"), ToolStrip1)
End Sub
(my mdiParent form is named 'MDIParent1')
 
JohnH,
That got them to show up the way I want but the stay after I remove the Child form.

I also had a problem with repeat adds when I created more than one child
 
You want to remove with mdichild? ToolStripManager.RevertMerge will do that. Example code in mdichild form:
VB.NET:
Private Sub Form2_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Deactivate
  ToolStripManager.RevertMerge(Me.MdiParent.Controls("ToolStrip1"), ToolStrip1)
End Sub
edit: this also handles multiple merges, since there can only be one active mdi child at a time.
 
Last edited:
I just want to thankyou so much again! It's working beautifullly! This forum, and the people on it have been so very helpful with their programming knowledge. So thankyou everyone for the great help you've been to me.

This project is very close to completion, thanks in part to all of you replying to my posts.

Kudos!:D
 
Here is example code that merges mdiChild toolstrip1 into mdiParent toolstrip1:
VB.NET:
Private Sub MDIParent1_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.MdiChildActivate
  ToolStripManager.Merge(Me.ActiveMdiChild.Controls("ToolStrip1"), ToolStrip1)
End Sub


What would happent if the ChildForm doesn't have ToolStrip or Closing the ChildForm?

VB.NET:
System.NullReferenceException: Object reference not set to an instance of an object.
 

Attachments

  • WindowsApplication.zip
    18.2 KB · Views: 33
Last edited by a moderator:
You can check both if ActiveMdiChild and the toolstrip requested is Nothing.
VB.NET:
If Me.ActiveMdiChild IsNot Nothing Then
    Dim ts As ToolStrip = Me.ActiveMdiChild.Controls("ToolStrip1")
    If ts IsNot Nothing Then ToolStripManager.Merge(ts, ToolStrip1)
End If
 
Back
Top