Creating contextmenustrip using all the dropdownitems from a toolstripmenuitem including toolstripseperator

Locked Creating contextmenustrip using all the dropdownitems from a toolstripmenuitem including toolstripseperator

  • 2012년 4월 28일 토요일 오전 7:19
     
     
    I have a Menustrip which displays a large number of menus and submenus. Like File, Edit, Master, transcation etc.. I want display a context menu dynamically generated from the submenus of menus strip please help...

모든 응답

  • 2012년 4월 30일 월요일 오전 9:27
    중재자
     
     

    Hi Shri,

    Welcome to the MSDN forum.

    To generate a menu strip dynamically, you can use the following codes:

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

            Dim ms As New MenuStrip()

            Dim testItem As New ToolStripMenuItem("Test", Nothing, New EventHandler(AddressOf item_Click))

            ms.Items.Add(testItem)

            Me.Controls.Add(ms)

            ms.Visible = True

        End Sub

        Private Sub item_Click(ByVal sender As Object, ByVal e As EventArgs)

            Stop

        End Sub

    This reference link may be helpful also: http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/2160832d-ebd3-476a-892d-2a1e1403b532

    If I misunderstood anything, please feel free and let me know.

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

  • 2012년 5월 9일 수요일 오전 9:53
     
     

     Thanks Shanks Zen,

    But I am Trying to generate Context menu using Menu Strip which is already created at design time. I want both the Menu Item and  Context menu Item should share a same event ... 

  • 2012년 5월 10일 목요일 오전 9:56
     
      코드 있음

    Hello

    A quick test on this, and can't a solution for binding event for them :(

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Dim Menu As New ContextMenuStrip()
            For Each t As ToolStripMenuItem In MenuStrip1.Items
                Dim test As New ToolStripMenuItem(t.Text)
                For Each s As ToolStripDropDownItem In t.DropDownItems
                    test.DropDownItems.Add(s.Text)
                Next
                Menu.Items.AddRange(New ToolStripItem() {test})
            Next
        End Sub
    
    Whatever, hope some members will jump into this case because I'm expecting a solution for this too.

  • 2012년 6월 23일 토요일 오전 4:53
     
     

    I have found the unique solution. 

    I just remove the dropdownitems of all the menustrip item and made them as a context menu.

     the context menu can be added to the MenustripItems dropdown Item. Something like

    MenuStripItem.DropDown =ContextMenu1

    this can be used for both Mwnu dropdown or Context menu having a same event.


    Shrinidhi Acharya

    • 답변으로 제안됨 Gagi78 2012년 10월 8일 월요일 오후 8:04
    • 답변으로 제안 취소됨 Gagi78 2012년 10월 8일 월요일 오후 8:04
    •  
  • 2012년 10월 8일 월요일 오후 8:07
     
     
    You can add lots of menu and context menu just make combination between them, and make proper combination for your solution.

    Gagi78