Creating contextmenustrip using all the dropdownitems from a toolstripmenuitem including toolstripseperator
-
2012년 4월 28일 토요일 오전 7:19I 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
- 답변으로 표시됨 Shanks ZenMicrosoft Contingent Staff, Moderator 2012년 5월 8일 화요일 오전 2:31
- 답변으로 표시 취소됨 Shrinidhi Acharya 2012년 5월 9일 수요일 오전 9:56
-
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 SubWhatever, 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
-
2012년 10월 8일 월요일 오후 8:07You can add lots of menu and context menu just make combination between them, and make proper combination for your solution.
Gagi78

