|
-
Mar 31st, 2006, 11:14 AM
#1
[RESOLVED] [2005] Context menu :(
Hello.
Could someone give me an example of how to add a new contextmenu item TO another item so it'll be a "submenu"?
lets say i want to add "Hello" to the already existing menu item "Good day".
Thanks!
-
Mar 31st, 2006, 11:24 AM
#2
Re: [2005] Context menu :(
Each menu item has a property named 'MenuItems' or something like that. You add other menu items to that collection and they become subitems and will be displayed automatically.
-
Mar 31st, 2006, 11:28 AM
#3
Re: [2005] Context menu :(
they havnt got any menu item like that
-
Mar 31st, 2006, 11:29 AM
#4
Re: [2005] Context menu :(
To create submenus, you can add MenuItem objects to the MenuItems property of the parent MenuItem.
VB Code:
'Will get you another cm menu item
Me.ContextMenu1.MenuItems.Add("Hello", New EventHandler(AddressOf cmPopup_Click))
'To add submenus
Me.ContextMenu1.MenuItems.Add(cmSubMenu1, New EventHandler(AddressOf cmPopupSub1_Click))
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2006, 11:55 AM
#5
Re: [2005] Context menu :(
 Originally Posted by Atheist
they havnt got any menu item like that 
You're using 2005 so I assume that you're using a ContextMenuStrip. It has an Items property, to which you can add ToolStripMenuItems, and each of them has a DropDownItems property, to which you can add more menu items. Here's some basic code to create a two level menu. You'd need to do a bit more work to make it do anything useful but this will give the visual element.
VB Code:
Me.ContextMenuStrip1.Items.Add("Hello")
Me.ContextMenuStrip1.Items.Add("World")
Me.ContextMenuStrip1.Items.Add("Goodbye")
Dim firstMenuItem As ToolStripMenuItem = DirectCast(Me.ContextMenuStrip1.Items(0), ToolStripMenuItem)
firstMenuItem.DropDownItems.Add("Item 1")
firstMenuItem.DropDownItems.Add("Item 2")
firstMenuItem.DropDownItems.Add("Item 3")
-
Mar 31st, 2006, 01:51 PM
#6
Re: [2005] Context menu :(
Thanks alot! I used jmcilhinney example and it works fine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|