C# – Capture the mouse right click event of a web browser control

cwebbrowser-controlwinforms

I would like to select all when a user right clicks on my web browser control.

I am developing a win forms app, and use web browsers to display my information, because i can use html to style the words.

The right click context menu is not working for me. The options on it are all irrelevant to my app.

But the context menu after a select has been made i want to keep, the copy, cut, paste options.

I can already select all:

getCurrentBrowser().Document.ExecCommand("SelectAll", true, null);

I would just like to do it in the right click event of the web browser?

Best Answer

Handle MouseDown event:

webBrowser.Document.MouseDown += new HtmlElementEventHandler(Document_MouseDown);

and make sure user pressed Right button, then select all:

void Document_MouseDown(object sender, HtmlElementEventArgs e)
{
    if(e.MouseButtonsPressed == MouseButtons.Right)
    {
        webBrowser.Document.ExecCommand("SelectAll", true, null);
    }
}
Related Topic