ykh
ykh

Reputation: 1825

Intercept IE Context Menu Click in WebBrowser Control

I am using WinForms, i have added a WebBrowser control and would like to able to intercept a context menu firing event for the IE browser since the browser control is an instance of IE.

I mean, i want to intercept the right click menu item click for the browser it self, i said to my self since it's an IE instance and it's inside my application, there got to be a way to do it.

I tried to look at the events of the browser control, but nothing there is nothing that would help me.

Thanks.

Upvotes: 0

Views: 1498

Answers (2)

andy
andy

Reputation: 6079

Set the below simple property of webbrowser control

wbBrowser.IsWebBrowserContextMenuEnabled = false;

Upvotes: 0

HABJAN
HABJAN

Reputation: 9338

Here is an example of canceling WebBrowser context menu. This will help you move on:

// wb = WebBrowser control instance name
// attach to the DocumentCompleted event
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);

void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // when the document loading is completed, attach to the document context showing event
    wb.Document.ContextMenuShowing += new HtmlElementEventHandler(Document_ContextMenuShowing);
}

void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e)
{
    // cancel showing context menu
    e.ReturnValue = false;
    // take a look at the 'e' parameter for everything else, you can get various information out of it
}

Upvotes: 2

Related Questions