【问题标题】:Detect when a click downloads a file in winforms WebBrowser component检测点击何时下载winforms WebBrowser组件中的文件
【发布时间】:2012-04-27 15:28:42
【问题描述】:

我有一个简单的网页,我的浏览器组件中只显示了 3 个链接:

<a href="/newpage1.html" id="el-1">Go to new page 1</a>
<a href="/newpage2.html" id="el-2">Go to new page 2</a>
<a href="/file.zip" id="el-1">Download file</a>

我为元素列表上的点击事件注册了一个事件处理程序

foreach (HtmlElement e in this.webBrowserMain.Document.GetElementsByTagName("a")){
    e.Click += this.SingleElementClickHandler;
}

假设服务器端为文件 /file.zip 发送了以下标头

header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="file.zip"');

如何编写 SingleElementClickHandler 以在下载文件时弹出带有文本“Hello”的消息框,而在打开另一个网页时

我不能使用任何第三方组件。

【问题讨论】:

    标签: c# winforms webbrowser-control


    【解决方案1】:

    简单

    this.webBrowserMain.FileDownload += 
        new EventHandler((x, y) => MessageBox.Show("Hello"));
    

    在搜索herethis SO 问题后找到了这个(即使它是 wpf 组件而不是 winforms 组件)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 2022-07-23
      相关资源
      最近更新 更多