Is there key press or similar event on context Menu?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Here is what I am trying to do using context menu.
I have a toolbar button with a style "Dropdown" that has a context menu in it,I am adding items dynamically to the context menu.I want to delete items from the context menu based on the right click "Delete" opition.
I couldn't find a key press or similar event on the context menu?
Can somebody please help.
Thanks for your help.
 
Hi Priy

If you whish to show or hide some context menu based on the right click of on object you can use Popup event of ContextMenu class. This fires before the menu is poping up

Sooraj
 
Hey Priya

I don't see how this is possible using the .net framework alone. But I think it may be possible using the Win32 API. What you should try is create a class inheriting from NativeWindow. Within the constructor call the Win32 API function CreatePopupWindow. This function returns a handle which (I think) you can assign to your native window using NativeWindow.AssignHandle. Afterwards you can add menuitems using the Win32 API function InsertMenu

To handle all messages send to the menu you must override NativeWindow.WndProc. That way you can also handle when the user right-clicks your menu so that you can create a new context menu for deleting menu items from the first menu

Regards, Jakob
This is all very cumbersome and I am not even sure that it will work. But I have done similar things using NativeWindow so there is a chance that it might work.
 
Hi Jakob/Sooraj
Thanks for your replies,But I find it too difficult to implement your suggestions
so I am trying to add submenu items to menu.But when I am at submenu ,I couldn't get the index of the previous menu,is there a way to get the index of the main menu
Below is the structure of my men
Favorite
.....url
....Browse1
....Delete1
......url
....Browse2
....Delete2
how to get the index of url1 when I am at the submenu Browse11
Thanks in advance
Priy
 
H

You can use the Parent property to get the parent menu of the Menuitem in the context menu

Ex: Vb.Ne

Dim menuItem1 as New MenuItem("&Delete"
Dim menuItem2 as New MenuItem("&Undo"
contextMenu.MenuItems.Add(menuItem1
contextMenu.MenuItems.Add(menuItem2
...........................

Dim menuParent as Menu = menuItem1.Paren

menuParent gives your Parent menu

Soora
Microsoft Community Sta
 
Back
Top