Resolved Multiuse of menus

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
216
Programming Experience
10+
Un-commenting the top items seems to prove a menu item can only be on one menu at a tie.

Un-commenting the lower items gives an error message - I don't know why.

On the form

VB.NET:
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        'This appears to work but the MenuItes are removed from the ContextMenu
        'Appears that a menu item can nt be on two menus
        'For i As Integer = 0 To ControlTextEditor_1.GetContextMenuStripGeneralItems.Count - 1
        '    MenuStrip_ForDisply.Items.Add(ControlTextEditor_1.GetContextMenuStripGeneralItems(i))
        'Next

        'This give a modifying collection error - do not know why seeing that GetContextMenuStripGeneralItems is not  MenuStrip_ForDisply.Items
        'For Each z As ToolStripMenuItem In ControlTextEditor_1.GetContextMenuStripGeneralItems
        '    MenuStrip_ForDisply.Items.Add(z)
        'Next

    End Sub
End Class

On the UserControl code

VB.NET:
  Public ReadOnly Property GetContextMenuStripGeneralItems() As ToolStripItemCollection
        Get
            Return ContextMenuStrip_General.Items
        End Get
    End Property

Looking for insight.

Do you believe a menuitem can only be on one menu at a time?

Why the error message from the second group?

Do you know where there is an example of multiuse of menus?

The entire solution is attached



PS I know I can do this:
Me.ToolStripMenuItem_ForDisplay_TextEditor.DropDown = ControlTextEditor_1.GetContextMenuStripGeneral
 

Attachments

  • Menu Tester.zip
    282.3 KB · Views: 8
Last edited:
Solution
Note A given ToolStripItem cannot have more than one parent ToolStrip. You must copy of the ToolStripItem and add it to other ToolStrip controls.
Un-commenting the top items seems to prove a menu item can only be on one menu at a tie.

Un-commenting the lower items gives an error message - I don't know why.
True. Because adding the item to another menu removes it from the current collection = collection change while iterating.
It is easy to copy items/branches of items in designer...
Note A given ToolStripItem cannot have more than one parent ToolStrip. You must copy of the ToolStripItem and add it to other ToolStrip controls.
Un-commenting the top items seems to prove a menu item can only be on one menu at a tie.

Un-commenting the lower items gives an error message - I don't know why.
True. Because adding the item to another menu removes it from the current collection = collection change while iterating.
It is easy to copy items/branches of items in designer: If you're adding items in code it is also easy to create two items instead of one.
The same event handler can be used for both copies.
 
Solution
Back
Top