Manage .NET WebBrowser - Get Active Context Menu

I have a WebBrowser control and I want when the right button is pressed and the context menu appears to get a handle to that context menu.

perhaps?

0
source share
2 answers

Yes.

You can reference the following code.

//this code assumes WebBrowser object(_webBrowser) is already initiated //in class scope. //this method is needed to execute when form is loaded. //Register it to load event private void Loaded(object sender, RoutedEventArgs e) { _webBrowser.LoadCompleted += _webBrowser_LoadCompleted; } private HTMLDocumentEvents2_Event _docEvent; private void _webBrowser_LoadCompleted(object sender, NavigationEventArgs e) { if (_docEvent != null) { _docEvent.oncontextmenu -= new HTMLDocumentEvents2_oncontextmenuEventHandler(_docEvent_oncontextmenu); } if (_webBrowser.Document != null) { _docEvent = (HTMLDocumentEvents2_Event)_webBrowser.Document; _docEvent.oncontextmenu += new HTMLDocumentEvents2_oncontextmenuEventHandler(_docEvent_oncontextmenu); } } bool _docEvent_oncontextmenu(IHTMLEventObj pEvtObj) { //do something and determine you want whether context menu shows or not //if you want to shows context menu, you'll need to return true. return true; } 
+1
source

If all you want to display your own contextMenu. I posted here a solution that works for the WebBrowser winforms control:

How do you override the ContextMenu that appears when you right-click on winforms WebBrowser Control?

+1
source

All Articles