Web Browser Right Click Capture Event

I would like to select everything when the user right-clicks on my web browser.

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

The right-click context menu does not work for me. The parameters on it are not related to my application.

But the context menu after the selection was made, I want to save, copy, cut, paste parameters.

I can already highlight everything:

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

I just wanted to do this in the right click event of a web browser?

+5
source share
4 answers

It works:)

, , , , , , ..

private void webCompareSQL_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (webCompareSQL.Document != null)
            {
                webCompareSQL.Document.ContextMenuShowing += DocMouseClick;
            }
        }
        void DocMouseClick(object sender, HtmlElementEventArgs e)
        {
            webCompareSQL.Document.ExecCommand("SelectAll", true, null);
        }
+2

MouseDown :

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

, "", :

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

, - .

, Javascript -, :

    document.oncontextmenu=new Function("return false")

WinForms, WPF, IsWebBrowserContextMenuEnabled false, IE, ContextMenu, WebBrowser.

WPF , -, . , , WindowsFormsHost - WinForms WPF.

+4

, WebBrowser.Document . .

`browser.DocumentCompleted += (s, e) => { 
                             browser.Document.MouseMove += (sM, eM) +=> { 
                                                          Debug.WriteLine (eM.ClientMousePosition.X); 
                                                                        };
                                       };
`
0
source

All Articles