Resolved The File menu shows the items from Form2 after the three File items from FormMain

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
No matther what I try the File menu shows the items from Form2 after the three File items from FormMain

The three MergeIndex from FormMain are 0, 5 and 6.

The three MergeIndex from Form2 are 2, 3 and 4.

Yet the File menu always shows the items from FormMain at the top followed by the items from Form2

Sorry about the length of the following.
At first I selected all the Merge code and was going to present only that but I was sure that someone would say there is not enought code.
And I believe that woud be correct.




FORMMAIN

VB.NET:
Public Class FormMain
    Private Sub InitializeComponent()
    
        '
        'menuStrip_General
        '
        menuStrip_General.Items.AddRange(New System.Windows.Forms.ToolStripItem() {menuItemFile, menuItemWindowMain, menuItemLayout})
        menuStrip_General.Location = New System.Drawing.Point(0, 0)
        menuStrip_General.Name = "menuStrip_General"
        menuStrip_General.Size = New System.Drawing.Size(528, 24)
        menuStrip_General.MdiWindowListItem = menuItemWindowMain
        menuStrip_General.AllowMerge = True
        menuStrip_General.TabIndex = 1
        menuStrip_General.Text = "menuStrip_General"
        'MainMenu.BackColor = Color.OrangeRed
        'MainMenu.ForeColor = Color.Black
        'MainMenu.Text = "File Menu"
        'MainMenu.Font = NewFont("Georgia", 16)
        'MainMenu.Dock = DockStyle.Left
        'ainMenu.BackColor = Color.OrangeRed
        'MainMenu.ForeColor = Color.Black
        '
        'menuItemFile
        '
        menuItemFile.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {menuItemNew, menuItemExitApp, menuItemCloseSelectedDocument})
        menuItemFile.MergeIndex = 0

        menuItemFile.Name = "menuItemFile"
        menuItemFile.Size = New System.Drawing.Size(64, 20)
        menuItemFile.Text = "&File"
        'FileMenu.BackColor = Color.OrangeRed
        'FileMenu.ForeColor = Color.Black
        'FileMenu.Text = "File Menu"
        'FileMenu.Font = NewFont("Georgia", 16)
        'FileMenu.TextAlign = ContentAlignment.BottomRight
        'FileMenu.TextDirection = ToolStripTextDirection.Vertical90
        'FileMenu.ToolTipText = "Click Me"
        '
        'menuItemNew
        '
        menuItemNew.MergeIndex = 0
        menuItemNew.MergeAction = MergeAction.Insert
        menuItemNew.Name = "menuItemNew"
        menuItemNew.Size = New System.Drawing.Size(147, 22)
        menuItemNew.Text = "&New Child Form (Main)"
        '
        'menuItemExitApp
        '
        menuItemExitApp.MergeIndex = 6
        menuItemExitApp.MergeAction = MergeAction.Insert
        menuItemExitApp.Name = "menuItemExitApp"
        menuItemExitApp.Size = New System.Drawing.Size(147, 22)
        menuItemExitApp.Text = "Exit App (Main)"
        '
        'menuItemCloseSelectedDocument
        '
        menuItemCloseSelectedDocument.MergeIndex = 5
        menuItemCloseSelectedDocument.MergeAction = MergeAction.Insert
        menuItemCloseSelectedDocument.Name = "menuItemCloseSelectedDocument"
        menuItemCloseSelectedDocument.Size = New System.Drawing.Size(147, 22)
        menuItemCloseSelectedDocument.Text = "Cl&ose Selected Document (Main)"
        '
        'menuItemWindowMain
        '
        menuItemWindowMain.MergeIndex = 3
        menuItemWindowMain.Name = "ToolStripMenuItemWindow (Main)"

        menuItemWindowMain.Size = New System.Drawing.Size(90, 20)
        menuItemWindowMain.Text = "&Window (Main)"
        '
        'menuItemLayout
        '
        menuItemLayout.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {menuItemAI, menuItemAcs, menuItemHoriz, menuItemVert, menuItemMax, menuItemMin})
        menuItemLayout.MergeIndex = 6
        menuItemLayout.Name = "menuItemLayout"
        menuItemLayout.Size = New System.Drawing.Size(82, 20)
        menuItemLayout.Text = "&Layout (Main)"
        '
        'menuItemAI
        '
        menuItemAI.MergeIndex = 0
        menuItemAI.Name = "menuItemAI"
        menuItemAI.Size = New System.Drawing.Size(201, 22)
        menuItemAI.Text = "Arrange&Icons (Main)"
        '
        'menuItemAcs
        '
        menuItemAcs.MergeIndex = 1
        menuItemAcs.Name = "menuItemAcs"
        menuItemAcs.Size = New System.Drawing.Size(201, 22)
        menuItemAcs.Text = "&Cascade (Main)"
        '
        'menuItemHoriz
        '
        menuItemHoriz.MergeIndex = 2
        menuItemHoriz.Name = "menuItemHoriz"
        menuItemHoriz.Size = New System.Drawing.Size(201, 22)
        menuItemHoriz.Text = "Arrange &Horizontal (Main)"
        '
        'menuItemVert
        '
        menuItemVert.MergeIndex = 3
        menuItemVert.Name = "menuItemVert"
        menuItemVert.Size = New System.Drawing.Size(201, 22)
        menuItemVert.Text = "Arrange &Vertical (Main)"
        '
        'menuItemMax
        '
        menuItemMax.MergeIndex = 4
        menuItemMax.Name = "menuItemMax"
        menuItemMax.Size = New System.Drawing.Size(201, 22)
        menuItemMax.Text = "Ma&ximize all (Main)"
        '
        'menuItemMin
        '
        menuItemMin.MergeIndex = 5
        menuItemMin.Name = "menuItemMin"
        menuItemMin.Size = New System.Drawing.Size(201, 22)
        menuItemMin.Text = "Mi&nimize all (Main)"
        '
        'openFileDlg
        '
        openFileDlg.AddExtension = False
        openFileDlg.Title = "MDI Sample"
        '
        'Form1
        '
        AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        ClientSize = New System.Drawing.Size(528, 401)
        Controls.Add(menuStrip_General)
        MainMenuStrip = menuStrip_General
        Name = "Form(Main)"
        Text = "MDI Example"
        IsMdiContainer = True
        StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        menuStrip_General.ResumeLayout(False)
        menuStrip_General.PerformLayout()
        ResumeLayout(False)
        PerformLayout()
    End Sub



End Class



FORM2

VB.NET:
#Region "Windows Form Designer generated code"

    Private Sub InitializeComponent()
      
        '
        ' menuStrip_General
        '
        menuStrip_General.Items.AddRange(New ToolStripMenuItem() {menuItemFile})
        menuStrip_General.Location = New System.Drawing.Point(0, 0)
        menuStrip_General.Name = "menuStrip_General"
        menuStrip_General.Size = New System.Drawing.Size(528, 24)
        menuStrip_General.AllowMerge = True
        menuStrip_General.TabIndex = 1
        menuStrip_General.Text = "menuStrip_General"

        menuStrip_General.Visible = False
        '
        ' menuItemFile
        '
        menuItemFile.DropDownItems.AddRange(New ToolStripMenuItem() {menuItemWM, menuItemOpen, menuItemSave})
        menuItemFile.MergeIndex = 0
        menuItemFile.MergeAction = MergeAction.MatchOnly
        menuItemFile.Name = "menuItemFile"
        menuItemFile.Size = New System.Drawing.Size(64, 20)
        menuItemFile.Text = "&File"
        '
        ' menuItemOpen
        '
        menuItemOpen.MergeIndex = 2
        menuItemOpen.MergeAction = MergeAction.Insert
        menuItemOpen.Name = "menuItemOpen"
        menuItemOpen.Size = New System.Drawing.Size(147, 22)
        menuItemOpen.Text = "&Open" & " (" & sCount & ")"
        '
        ' menuItemWM
        '
        menuItemWM.MergeIndex = 3
        menuItemWM.MergeAction = MergeAction.Insert
        menuItemWM.Text = "&Watermark" & " (" & sCount & ")"
        '
        ' menuItemSave
        '
        menuItemSave.MergeIndex = 4
        menuItemSave.MergeAction = MergeAction.Insert
        menuItemSave.Text = "&Save" & " (" & sCount & ")"
        '
        ' openFileDlg
        '
        openFileDlg.AddExtension = False
        openFileDlg.Title = "MDI Sample" & " (" & sCount & ")"
        '
        ' panel1
        '
        panel1.AutoScroll = True
        panel1.Controls.AddRange(New Control() {pictureBox1})
        panel1.Location = New Point(8, 0)
        panel1.Name = "panel1"
        panel1.Size = New Size(280, 264)
        panel1.TabIndex = 0
        '
        ' pictureBox1
        '
        pictureBox1.Location = New Point(16, 16)
        pictureBox1.Name = "pictureBox1"
        pictureBox1.Size = New Size(248, 224)
        pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
        pictureBox1.TabIndex = 0
        pictureBox1.TabStop = False
        '
        ' saveFileDlg
        '
        saveFileDlg.FileName = "doc1"
        '
        ' Form2
        '
        AutoScaleBaseSize = New Size(5, 13)
        ClientSize = New Size(292, 273)
        Controls.AddRange(New Control() {panel1})
        Controls.Add(menuStrip_General)
        MainMenuStrip = menuStrip_General
        Name = "Form2"
        Text = "Child" & " (" & sCount & ")"
        WindowState = FormWindowState.Maximized
        panel1.ResumeLayout(False)
        menuStrip_General.ResumeLayout(False)
        menuStrip_General.PerformLayout()
        ResumeLayout(False)
        PerformLayout()
    End Sub

  

#End Region

  

End Class
 
Last edited:
Solution
I just created a test project with two forms that look like this:

1617201964241.png


and this:

1617201997665.png


I set the Visible property of the child MenuStrip to False. I set the MergeAction of the child File menu item to MatchOnly and of the other two child menu items to Insert. I set the MergeIndex of the Child1 and Child2 menu items to 1 and 0 respectively. I added this code to Form1:
VB.NET:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim f2 As New Form2 With {.MdiParent = Me}

    f2.Show()
End Sub
When I ran the project, this is what I saw:

1617202737437.png


What's happened there is that the two child menu items have been...
Please don't post every line of code you have because it's a huge waste of our time wading through all of it to find the part that's relevant. If culling the irrelevant code from your application is a problem then don't post any of it. Create a new test application that contains only what is absolutely necessary to demonstrate the issue and then post that code. You should do everything you can to help us help you.
 
Please don't post every line of code you have because it's a huge waste of our time wading through all of it to find the part that's relevant. If culling the irrelevant code from your application is a problem then don't post any of it. Create a new test application that contains only what is absolutely necessary to demonstrate the issue and then post that code. You should do everything you can to help us help you.
I'll edit some of it out

DONE.

Think I should take more out?
 
Last edited:
Try MergeIndex = 1 for the three child items.

You don't need merge settings for main menu, because it is not being merged into another menu.
 
Last edited:
I just created a test project with two forms that look like this:

1617201964241.png


and this:

1617201997665.png


I set the Visible property of the child MenuStrip to False. I set the MergeAction of the child File menu item to MatchOnly and of the other two child menu items to Insert. I set the MergeIndex of the Child1 and Child2 menu items to 1 and 0 respectively. I added this code to Form1:
VB.NET:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim f2 As New Form2 With {.MdiParent = Me}

    f2.Show()
End Sub
When I ran the project, this is what I saw:

1617202737437.png


What's happened there is that the two child menu items have been inserted into the parent menu sequentially, so the index of the first has been affected by the second. Initially, the parent menu contains two items (Parent1 and Parent2) at indexes 0 and 1. The first child menu item encountered is Child1 and it gets inserted at index 1, so between Parent1 and Parent2. The next child menu item encountered is Child2 and it gets inserted at index 0, so before Parent1. That pushes the other items down one place, so Child1 ends up at index 2, even though the MergeIndex was 1. Hopefully this demonstrates how and why you need to set the properties of the child menu and items to get the merge you want. You don't have to do anything to the parent menu and items.
 
Last edited:
Solution
The three MergeIndex from FormMain are 0, 5 and 6.

The three MergeIndex from Form2 are 2, 3 and 4.
That doesn't seem to make sense because there's no index 1. Assuming that you want the first parent menu item to be followed by the three child menu items and then followed by the other two parent items, you should be setting the child MergeIndex values to 1, 2 and 3. I just edited my forms to be like that and I went from this:

1617203520178.png


and this:

1617203544372.png


to this:

1617203569218.png


Simples!
 
EDIT: My e-mail opened the browser at the last jmcihinney post. I did not see the one before that until just now. After I studied that post I fixed my code so I deleted what I had here.
 
Last edited:
No, you set merge settings for a menu that will be merged into another, that's their only use. AllowMerge, MergeIndex and MergeAction does nothing in your main form.

Your child item order is {menuItemWM, menuItemOpen, menuItemSave}, but you set them to insert at indexes {2,1,3}, when it should be {1,2,3}.
 
No, you set merge settings for a menu that will be merged into another, that's their only use. AllowMerge, MergeIndex and MergeAction does nothing in your main form.

You child item order is {menuItemWM, menuItemOpen, menuItemSave}, but you set them to insert at indexes {2,1,3}, when it should be {1,2,3}.
Not really knowing how it worked I thought I could change the order on the main menu. I understand better now how merge works.
 
Last edited by a moderator:

Latest posts

Back
Top