我需要在 WinForm C# 中捕获 WebBrowser 控件的拖放事件。有什么办法吗?
最佳答案
我的解决方法:
使用 bool 成员变量来检测您是从内部代码调用导航还是从外部代码调用导航。实现“导航”(BeforeNavigating)事件并检查它是否是来自外部的调用。
例子:
从内部调用导航:
private void NavigateLocal(string htmlFileName)
{
this.localNavigate = true;
this.webBrowser.Navigate(htmlFileName);
}
事件方法:
private void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (this.localNavigate)//inside call
{
this.localNavigate = false;
}
else //call from outside
{
this.DoDragDrop(e.Url.ToString());
}
}
关于winforms - 实现拖放功能 WebBrowser Control Winforms C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1361007/