I need programmatically to show a sub-menu of main menu on a form in Winform .NΕΤ application (classes MainMenu with MenuItem).
- E.g. show sub-menu with all items of menu item File.
- E.g. same as pressing Alt-F if menu item text is &File.
I have tried to call OnPopup(), PerformClick(), PerformSelect(), and sending WM_MenuSelect message; sub-menu does not open.
Is there a way to do it?
To show a menu item of a legacy
MainMenucomponent, you need to callTrackPopupMenuExand pass the menu item handle to it. To show it in the correct location, as when you click on the menu item, get the menu item rectangle usingGetMenuItemRect.Here is the code:
To use it, just call it this way:
If you call it by passing false to
showAxContextMenu, it will show the sub menu in the mouse position: