Webbrowser control closing, how to port to C# . Calling all pros, please

G

Guest

Hi! I have a winform with embedded webbrowser control. When a user navigates to a page that has a link or a button that calls windows.close() javascript, the control closes yet the form does not. Since the control does not expose the onQuit() event, I need to capture the message and close my winform. I found the following Microsoft article that explains on how to do it in C++. I recently switched from Cold Fusion and have a heck of a time figuring out how to port the C++ code to C#.

Please help. I can email you the test form to try

Article URL

http://support.microsoft.com/defaul...port/kb/articles/q253/2/19.asp&NoWebContent=1
 
A

Andy Gaskell

I was able to get it working using the method described in this post -
http://tinyurl.com/2uafs

I had to make a few modifications:

Add a field to the IEEvents class.
private Form form;

Add a constructor to the IEEvents class
public IEEvents(Form form)
{
this.form = form;
}

When you instaniate the IEEvents class, be sure to pass in the form.
IEEvents e = new IEEvents(this);


Change the code inside the WindowClosing method
Cancel = true;
//Display custom yes/no messagebox if you want, for now just assume that
you want the form closed
this.form.Close();



Mike Z... said:
Hi! I have a winform with embedded webbrowser control. When a user
navigates to a page that has a link or a button that calls windows.close()
javascript, the control closes yet the form does not. Since the control does
not expose the onQuit() event, I need to capture the message and close my
winform. I found the following Microsoft article that explains on how to do
it in C++. I recently switched from Cold Fusion and have a heck of a time
figuring out how to port the C++ code to C#.
Please help. I can email you the test form to try.

Article URL.
http://support.microsoft.com/defaul...port/kb/articles/q253/2/19.asp&NoWebContent=1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top