1

How can I disable the standard-contextmenu of the WPF WebBrowser-Control?

H.B.
  • 166,899
  • 29
  • 327
  • 400
BennoDual
  • 5,865
  • 15
  • 67
  • 153
  • Good question, +1up. This may be helpful http://stackoverflow.com/questions/5507734/disable-context-menu-on-webbrowser-in-wpf – ToddBFisher Jun 07 '12 at 19:44
  • possible duplicate of [How to deactivate "right click" on WPF Webbrowser Control?](http://stackoverflow.com/questions/4412915/how-to-deactivate-right-click-on-wpf-webbrowser-control) – Hans Passant Jun 08 '12 at 00:37

1 Answers1

1

using mshtml;

    private mshtml.HTMLDocumentEvents2_Event documentEvents;

in constructor or xaml set your LoadComplete event:

   webBrowser.LoadCompleted += webBrowser_LoadCompleted;

then in that method create your new webbrowser document object and view the available properties and create new events as follows:

private void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
    documentEvents = (HTMLDocumentEvents2_Event)webBrowserChat.Document; // this will access the events properties as needed
    documentEvents.oncontextmenu += webBrowserChat_ContextMenuOpening;
}

private bool webBrowserChat_ContextMenuOpening(IHTMLEventObj pEvtObj)
{
    return false; // ContextMenu wont open
    // return true;  ContextMenu will open
    // Here you can create your custom contextmenu or whatever you want
}
Devdude
  • 99
  • 7