Reputation: 1809
I have to code a program for a library, I have to embed a Web Browser for a website but the Web Browser can’t be close. So I have cancel closing but when a user clicks on a button in JS for closing window (window.Close) the program crash. I add :
HtmlDocument htmlDocument = this.webBibliotheque.Document;
htmlDocument.Window.Unload += new HtmlElementEventHandler(Window_Unload);
when the Document is charged. This code works and gets to catch the evenment but I don’t know what I have to do in my function :
void Window_Unload(object sender, HtmlElementEventArgs e)
{
}
Can anyone help me please?
Upvotes: 1
Views: 2000
Reputation: 61666
You should handle the WindowClosing
event on the underlying WebBrowser
ActiveX Control (WebBrowser.ActiveXInstance
). There is an option to cancel it (disclaimer: untested). Check this answer for more details on how to handle the "raw" WebBrowser events like this.
Upvotes: 1