Adding to DefaultContextMenu

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by Rick - Developer, Visual Software Systems LLC
Avatar
I like the default context menu but want to add to it. I can do this through code as follows:

        Dim mnu As ContextMenu

        With editor
            mnu = .GetDefaultContextMenu
            mnu.MenuItems.Add(New MenuItem("Menu Item 1"))
            mnu.MenuItems.Add(New MenuItem("Menu Item 2"))
            .ContextMenu = mnu
        End With
When I run this code, the default context menu comes up with the additional items that I've added appearing at the bottom. However, the items in the original context menu become "inactive". Is there a way to add to the menu and keep the default functionality active? I'd really like to use the functionality that's already built-in rather than recoding it.

Thanks... Rick

Comments (2)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Rick,

I just tried this code and it works... this is the preferred way to handle context menus.
private void editor_ContextMenuRequested(object sender, ActiproSoftware.SyntaxEditor.ContextMenuRequestEventArgs e) {
    ContextMenu menu = editor.GetDefaultContextMenu();
    menu.MenuItems.Add(new MenuItem("Custom Item"));
    menu.Show(editor, e.MenuLocation);
    editor.DefaultContextMenuEnabled = false;
}
Hope that helps!


Actipro Software Support

Posted 19 years ago by Rick - Developer, Visual Software Systems LLC
Avatar
It does exactly what I wanted. Thanks for the help.
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.