Creating contextmenustrip using all the dropdownitems from a toolstripmenuitem including toolstripseperator
-
Saturday, April 28, 2012 7:19 AMI 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...
All Replies
-
Monday, April 30, 2012 9:27 AMModerator
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
- Marked As Answer by Shanks ZenMicrosoft Contingent Staff, Moderator Tuesday, May 08, 2012 2:31 AM
- Unmarked As Answer by Shrinidhi Acharya Wednesday, May 09, 2012 9:56 AM
-
Wednesday, May 09, 2012 9:53 AM
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 ...
-
Thursday, May 10, 2012 9:56 AM
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 SubWhatever, hope some members will jump into this case because I'm expecting a solution for this too.
-
Saturday, June 23, 2012 4:53 AM
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
-
Monday, October 08, 2012 8:07 PMYou can add lots of menu and context menu just make combination between them, and make proper combination for your solution.
Gagi78

