Welcome Guest Search | Active Topics | Sign In | Register

WebBrowser disable context menu Options
Mike King
Posted: Tuesday, July 2, 2019 8:01:17 PM
Rank: Newbie
Groups: Member

Joined: 6/14/2019
Posts: 5
I use a custom context menu for several web pages. It's a .Net object that interacts with the javascript.

I can get the context menu to display without any issues - I'm using the BeforeContextMenu event, maybe that's the wrong event to use. I can't disable or remove the web browser context menu. I've tried the standards - menu.items.cliear and contextmenu=null, that didn't do anything.

How do I completely remove or disable the default context menu? Mine appears above it, but the top four entries are unusable - the clicks are captured by the standard menu although it is underneath.

Thanks for your assistance.
Mike King
Posted: Tuesday, July 2, 2019 8:26:14 PM
Rank: Newbie
Groups: Member

Joined: 6/14/2019
Posts: 5
I managed to accomplish this by capturing the event with jsinitcode and capturing the right click. Not sure that's the best method, but it moves me forward. If there's a better/preferred way, please let me know.
eo_support
Posted: Wednesday, July 3, 2019 10:43:13 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

Yes. Your solution would work. There are three different context menus involved:

1. The WebControl's ContextMenu. This menu is the ContextMenu control that you associated to the WebControl in your host application. For example, for Windows Form application, this would be a ContextMenu/ContextMenuStrip that you associate to the control in the Form designer. If this context menu is set, then the context menu for step 2 is ignored;
2. The WebView's context menu. This is the default context menu provided by the browser engine. It has a few standard context menu items such as Back, Forward, Print, etc. This context menu can be overridden through BeforeContextMenu event;
3. The web page's context menu. This is the JavaScript code that responds to mouse right click and display some UI elements. This is no different than JavaScript code that responds a button clicks and invokes alert to display a message box. One way to avoid this is to modify the page's code in order to modify its behavior, this is essentially what you are doing.

The other way to do this is to "eat" the right mouse button up message. This will prevent all context menus. The code would be something like this:

Code: C#
private class MsgFilter : EO.WebBrowser.IInputMsgFilter
{
    InputMsgTarget IInputMsgFilter.PreDispatchMsg(int Msg, IntPtr wParam, IntPtr lParam)
    {
        //0x204 = WM_RBUTTONDOWN
        //0x205 = WM_RBUTTONUP
        if ((Msg == 0x0204) || (Msg == 0x205))
            return InputMsgTarget.None;

        return InputMsgTarget.Application;
    }
}

webView.InputMsgFilter = new MsgFilter();


This will short circuit both right mouse button down and right mouse button up message thus would prevent all context menus. Since it would prevent all context menus, your solution might work better for your case since when you do it with JavaScript, it only prevent context menu #3.

Hope this helps.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.