Apparently the Me.Popup doesn't work in VB.NET, and the Help Contents aren't helping. How do i show a Contextmenu that I've already created at design time? Thanks!
Printable View
Apparently the Me.Popup doesn't work in VB.NET, and the Help Contents aren't helping. How do i show a Contextmenu that I've already created at design time? Thanks!
If the Help contents aren't helping then it's most likely because you're looking in the wrong place. First up, is it a Windows Forms ContextMenu, a Windows Forms ContextMenuStrip or a WPF ContextMenu? Secondly, under what circumstances do you want the menu displayed because, if it's on a right-click, you probably don't need any code at all?
I think it's a Windows Form Contextmenu
And i want a menu displayed in a picturebox/imagebox mousedown event (right click)
set your picturebox's contextmenustrip property then run your project + right click the picturebox
I could only find ContextMenu, and it won't let me edit it in the properties menu :(
i just checked vb2005 + 8 + 10 windows forms
they all have a contextmenustrip property for the picturebox
Maybe its because i migrated this from VB 6.0... i will keep trying though. thanks :)
What version of VB.NET are you using? If it's 2002 or 2003 then you will have a ContextMenu item in the Toolbox and each control will have a ContextMenu property. If it's 2005, 2008 or 2010 then you will have a ContextMenuStrip item in the Toolbox and each control will have a ContextMenuStrip property. They are both very similar and do the same job. Either way, add an item to the form from the Toolbox, add items to the menu in the designer and assign the menu to the appropriate property of the desired control. When you right-click the control, the menu will be displayed.
It's either 2002 or 2003. But, do i have to create all my items from scratch? I have these menus that were made from the Menu Editor in VB 6.0 and they're just sitting on top of my form. I can reference them and everything but the one thing I can't do is show them. (I can show contextmenus created from scratch though).
Plus I can't see how to assign an event when you click on an item in the "new" contextmenu anyways :( Sorry newbie question!
I'm afraid I have no knowledge of how menus upgraded from VB6 behave. I would suggest recreating them regardless.
A MenuItem object has a Click event, just like a Button. Just like a Button, you double-click it in the designer to generate a Click event handler.
Ok I can recreate them. Thanks
But still having trouble with these "new" contextemenus... I see the click event like you said but where's the event for clicking a specific item in that contextemenu? Plus I can only seem to assign items to it at runtime...
there's an overload of the menuitem.add method where you can specify a click event handler.
You're trying to make this difficult when it's not. As I have already said, to create a handler for the Click event of a MenuItem, you double-click that MenuItem in the designer, just as you do with a Button.
Ok thank you paul and Jmcil. It turned out the old menus I had were messing up adding contextmenus to the top of the form. Which i was then able to add events for like you said x) . Thanks!