Solved

Programattically create context menu sub items

Posted on 2006-11-01
8
1,272 Views
Last Modified: 2012-08-13
I would like to create a context menu that has "Variable", "Static"
then I want to create sub items programatically?  how would I do that?

This is what i want to acheive

Variable
    x
    y
    z
Static
    q
    w  
    e

but I want to add xyz dynamically.

Thanks
0
Comment
Question by:wildrobo
  • 3
  • 2
  • 2
8 Comments
 
LVL 17

Expert Comment

by:ZeonFlash
Comment Utility
           Dim newMenu As MenuItem

            newMenu = New MenuItem("x")
            ContextMenu1.MenuItems(0).MenuItems.Add(newMenu)
            newMenu = New MenuItem("y")
            ContextMenu1.MenuItems(0).MenuItems.Add(newMenu)
            newMenu = New MenuItem("z")
            ContextMenu1.MenuItems(0).MenuItems.Add(newMenu)
0
 

Author Comment

by:wildrobo
Comment Utility
Thanks I tried it but I get

'MenuItems' is not a member of 'System.Windows.Forms.ContextMenuStrip'

Any thoughts?
0
 
LVL 17

Expert Comment

by:ZeonFlash
Comment Utility
Ahhh, you're using VS2005.  The ContextMenuStrip replaced VS2003's ContextMenu.  I don't personally use VS2005, so hopefully someone else can help!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:wildrobo
Comment Utility
Thanks, Sorry I should have clarified.  I am just finding out now that the contectmenustip is what to use in vs2005, but not finding much help.  Thank you for your time.
0
 
LVL 10

Expert Comment

by:Kinger247
Comment Utility
This is how you do it in vs2005 ....

you create the sub item and assign it to the main menu item ... then add it to your ContextMenuStrip !

        Dim contextMenuStrip As ContextMenuStrip
        Dim firstItem As ToolStripMenuItem
        Dim subItem As ToolStripMenuItem

        contextMenuStrip = New ContextMenuStrip()
        firstItem = New ToolStripMenuItem("level one")
        subItem = New ToolStripMenuItem("level two")

        firstItem.DropDownItems.Add(subItem)
        contextMenuStrip.Items.Add(firstItem)

the only documentation is on Mars.
cheers ..
0
 
LVL 10

Expert Comment

by:Kinger247
Comment Utility
oh, and if you want to add an event handler ... which I guess you will !

        Dim contextMenuStrip As ContextMenuStrip
        Dim firstItem As ToolStripMenuItem
        Dim subItem As ToolStripMenuItem

        contextMenuStrip = New ContextMenuStrip()
        firstItem = New ToolStripMenuItem("level one")
        subItem = New ToolStripMenuItem("level two")
        AddHandler SubItem.Click, AddressOf BorderThicknessMinusSprite

        firstItem.DropDownItems.Add(subItem)
        contextMenuStrip.Items.Add(firstItem)

Theres no intellisense for the SubItem.Click .....
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
Comment Utility
Hi wildrobo, did this work for you ?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now