捕获和处理Web浏览器关闭事件 [英] Catching and handling Web Browser Close Event

查看:133
本文介绍了捕获和处理Web浏览器关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows窗体和WebBrowser控件,我需要捕捉和处理的WebBrowser控件调用来关闭的。

I am Using Windows Forms and a WebBrowser Control, I am in need of catching and handling the WebBrowser Controls call to close.

我已经看过这一点,但它不工作,因为我需要它:的 http://blogs.artinsoft.net/Mrojas/archive/2009/05/21/Extended-WebBrowser-Control-Series-WebBrowser-Control-and-windowClose()的.aspx

I have looked at this but it is not working as I need it to: http://blogs.artinsoft.net/Mrojas/archive/2009/05/21/Extended-WebBrowser-Control-Series-WebBrowser-Control-and-windowClose().aspx

这是我得到的消息:

---------------------------
Web Browser
---------------------------
The webpage you are viewing is trying to close the window.

Do you want to close this window?
---------------------------
Yes   No   
---------------------------

我需要搭上这一事件,并压制它,在那之后执行的功能。有谁知道一个简单的方法来做到这一点?

I need to catch this event and suppress it, then perform a function after that. Does anyone know a simple way to do this?

推荐答案

到处搜寻,并没有真正得到什么,我需要后,我设法绊倒到一个偶然的参考:

After searching everywhere and not really getting what I needed, I managed to stumble onto a by chance reference:

HtmlDocument htmlDocument = this.webBrowser1.Document;
htmlDocument.Window.Unload += new HtmlElementEventHandler(Window_Unload);



文档没有WebBrowser控件之前得到卸载已关闭和处置。

The Document does get Unloaded before the WebBrowser Control is closed and disposed.

void Window_Unload(object sender, HtmlElementEventArgs e)
{
    // Do your stuff here...
    // Call Method...
    // Close Form...
}

这就是现在为我工作。

这篇关于捕获和处理Web浏览器关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆