在 Web 浏览器文档中获取 MouseClick 坐标时出错

问题描述 投票:0回答:1

该表单有 3 个 WebBrowser 控件,我需要知道哪一个发起了该事件。 我尝试使用 HtmlElementEventArgs 的 ClientMousePosition 属性来获取点击点,但编译器说:
<'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?)'>
虽然我可以在调试器中看到它。

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

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

出了什么问题?

c# winforms webbrowser-control
1个回答
0
投票

出了什么问题?

您需要更新 DocLinkClick 方法的定义,并将第二个参数中的 EventArgs 替换为 HtmlElementEventArgs。然后就可以直接在代码中使用ClientMousePosition属性了。

private void DocLinkClick(object sender, HtmlElementEventArgs e)
{
    MessageBox.Show(e.ClientMousePosition.ToString());
}
© www.soinside.com 2019 - 2024. All rights reserved.