1

The form has 3 WebBrowser controls and I need to know which one originated the event. I try using the ClientMousePosition property of HtmlElementEventArgs to get the click point, but the compiler says:
<'EventArgs' does not contain a definition for 'ClientMousePosition' and no accessible extension method 'ClientMousePosition' accepting a first argument of type 'EventArgs' could be found (are you missing a using directive or an assembly reference?)'>
although I can see it in the debugger.

private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
{
brRList.Document.Click += new HtmlElementEventHandler(this. DocLinkClick);
...
}

private void DocLinkClick(object sender, System.EventArgs e)
{
Point ClickPt = ClientMousePosition;
...
}

What is wrong?

alexb
  • 23
  • 1
  • 5
  • [Getting mouse click coordinates in a WebBrowser Document](https://stackoverflow.com/a/54232729/7444103) / [Download Image under the Mouse pointer via WebBrowser](https://stackoverflow.com/a/56169490/7444103) -- You should replace the old (deprecated) WebBrowser Control with [WebView 2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) – Jimi Aug 15 '23 at 06:36

1 Answers1

0

What is wrong?

You need to update the definition of the DocLinkClick method and replace the EventArgs by HtmlElementEventArgs in the second parameter. Then you can use the property ClientMousePosition directly in the code.

private void DocLinkClick(object sender, HtmlElementEventArgs e)
{
    MessageBox.Show(e.ClientMousePosition.ToString());
}
Sergey
  • 581
  • 1
  • 5
  • 12