gpt4 book ai didi

c# - 检测点击何时下载 winforms WebBrowser 组件中的文件

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:28 24 4
gpt4 key购买 nike

我有一个简单的网页,在我的网络浏览器组件中只显示了 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

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

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

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

最佳答案

简单

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

经过更多搜索后发现了这个 herethis SO问题(即使它是wpf组件而不是winforms组件)。

关于c# - 检测点击何时下载 winforms WebBrowser 组件中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10353454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com