Home All Groups Group Topic Archive Search About

windowclosing not firing

Author
21 Aug 2006 8:36 AM
Chad
Hi

In vb.net if you add a webbrowser control the windowclosing event does not
fire. I have searched everywhere for a solution rather I get more people
saying I have the same problem.

I found this...Could someone please convert this to VB.NET to give us a
glimmer of hope OR provide a solution.

If u implement axWebBrowser, you'll find the WindowClosing event doesn't
fire. This is the work around, which I confirm works.

1. Right below the System.Windows.Forms.Form class add another class
whichderives from SHDocVw.DWebBrowserEvents2. For example:\

public class IEEvents: SHDocVw.DWebBrowserEvents2
{}

2. Save the file and go to class view (View | Class View menu option). Go to
IEEvents class in the tree view and expand it. Keep expanding its children
till you see 'DWebBrowserEvents'. Right click and select 'Add | Implement
interfaces' menu option.

3. A method for WindowClosing event should be generated by above step. Apply
the 'DispId' attribute to the method as shown below:

[DispId(0x00000107)]
public void WindowClosing(bool IsChildWindow, ref bool Cancel)
{
//message box to the event handler works
   MessageBox.Show("Closing Event", "IE", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}

4. Add the following lines of code to the end of the Forms
'InitializeComponent' method.

UCOMIConnectionPointContainer pConPtCon =
(UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
UCOMIConnectionPoint pConPt;
Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
pConPtCon.FindConnectionPoint(ref guid, out pConPt);
IEEvents e = new IEEvents();
//make sure you declare private int dwCookie in the form class but outside
this method
pConPt.Advise(e, out dwCookie);

5. Add the following lines of code to the beginning of the Forms Close
handler method.

UCOMIConnectionPointContainer pConPtCon =
(UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
UCOMIConnectionPoint pConPt;
Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
pConPtCon.FindConnectionPoint(ref guid, out pConPt);
pConPt.Unadvise(dwCookie);

URL:http://www.kbcafe.com/iBLOGthere4iM/?guid=20040501150250

Thank-you and regards
Chad

Author
21 Aug 2006 1:24 PM
Chris Dunaway
Chad wrote:
> Hi
>
> In vb.net if you add a webbrowser control the windowclosing event does not
> fire. I have searched everywhere for a solution rather I get more people
> saying I have the same problem.

I cannot duplicate your error using VB.Net 2005.   I dragged a
WebBrowser control to the form.  I then added a FormClosing event.  The
event fired normally when I closed the form.  Perhaps I am
misunderstanding the problem.

Can you post a short but complete program that illustrates the problem?

Chris
Author
22 Aug 2006 1:09 AM
Chad
Thanks Chris

I should of been more detailed.

If you access a html page with java script to close the form the
windowclosing event is not fired through the webbrowser. It works in VB6 but
not VB.NET which is very annoying.

I have set up an example for you, add the code and click on the close button.

In vb6
Add the webbrowser control and this code...
Private Sub Form_Load()
  WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
End Sub

Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean, Cancel
As Boolean)
  MsgBox "WindowClosing Fired"
End Sub

Now in VB.NET add the webbrowser and this code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
    AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
  End Sub

  Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
AxWebBrowser1.WindowClosing
    MessageBox.Show("WindowClosing Fired")
  End Sub

The WindowClosing event is not fired and thus the messagebox is not shown...

Why and how do I fix this???

Show quoteHide quote
"Chris Dunaway" wrote:

> Chad wrote:
> > Hi
> >
> > In vb.net if you add a webbrowser control the windowclosing event does not
> > fire. I have searched everywhere for a solution rather I get more people
> > saying I have the same problem.
>
> I cannot duplicate your error using VB.Net 2005.   I dragged a
> WebBrowser control to the form.  I then added a FormClosing event.  The
> event fired normally when I closed the form.  Perhaps I am
> misunderstanding the problem.
>
> Can you post a short but complete program that illustrates the problem?
>
> Chris
>
>
Author
22 Aug 2006 4:51 AM
Cor Ligthert [MVP]
Chad,

I assume that your samples are a little bit mixed up, however.

The events in the 2.0 webbrowser are very very very much inferior to the
ones in the AxWebbrowser. As Herfried ones showed is it possible to create
workarounds for those. I don't know a workaround for this one.

Maybe if there are no returned documents.

Cor

Show quoteHide quote
"Chad" <C***@discussions.microsoft.com> schreef in bericht
news:1F5FAF74-72F7-4D26-B958-452B9F823CBC@microsoft.com...
> Thanks Chris
>
> I should of been more detailed.
>
> If you access a html page with java script to close the form the
> windowclosing event is not fired through the webbrowser. It works in VB6
> but
> not VB.NET which is very annoying.
>
> I have set up an example for you, add the code and click on the close
> button.
>
> In vb6
> Add the webbrowser control and this code...
> Private Sub Form_Load()
>  WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
> End Sub
>
> Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,
> Cancel
> As Boolean)
>  MsgBox "WindowClosing Fired"
> End Sub
>
> Now in VB.NET add the webbrowser and this code
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>    AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
>  End Sub
>
>  Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal e
> As
> AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
> AxWebBrowser1.WindowClosing
>    MessageBox.Show("WindowClosing Fired")
>  End Sub
>
> The WindowClosing event is not fired and thus the messagebox is not
> shown...
>
> Why and how do I fix this???
>
> "Chris Dunaway" wrote:
>
>> Chad wrote:
>> > Hi
>> >
>> > In vb.net if you add a webbrowser control the windowclosing event does
>> > not
>> > fire. I have searched everywhere for a solution rather I get more
>> > people
>> > saying I have the same problem.
>>
>> I cannot duplicate your error using VB.Net 2005.   I dragged a
>> WebBrowser control to the form.  I then added a FormClosing event.  The
>> event fired normally when I closed the form.  Perhaps I am
>> misunderstanding the problem.
>>
>> Can you post a short but complete program that illustrates the problem?
>>
>> Chris
>>
>>
Author
22 Aug 2006 6:11 AM
Chad
Hi Cor

Sorry, I dont understand what you mean...

VB6 works VB.NET does not work.

Please try the examples.

If there is no work around does VS.NET 2005 offer any hope???

Regards
Chad

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Chad,
>
> I assume that your samples are a little bit mixed up, however.
>
> The events in the 2.0 webbrowser are very very very much inferior to the
> ones in the AxWebbrowser. As Herfried ones showed is it possible to create
> workarounds for those. I don't know a workaround for this one.
>
> Maybe if there are no returned documents.
>
> Cor
>
> "Chad" <C***@discussions.microsoft.com> schreef in bericht
> news:1F5FAF74-72F7-4D26-B958-452B9F823CBC@microsoft.com...
> > Thanks Chris
> >
> > I should of been more detailed.
> >
> > If you access a html page with java script to close the form the
> > windowclosing event is not fired through the webbrowser. It works in VB6
> > but
> > not VB.NET which is very annoying.
> >
> > I have set up an example for you, add the code and click on the close
> > button.
> >
> > In vb6
> > Add the webbrowser control and this code...
> > Private Sub Form_Load()
> >  WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
> > End Sub
> >
> > Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,
> > Cancel
> > As Boolean)
> >  MsgBox "WindowClosing Fired"
> > End Sub
> >
> > Now in VB.NET add the webbrowser and this code
> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> >    AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
> >  End Sub
> >
> >  Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal e
> > As
> > AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
> > AxWebBrowser1.WindowClosing
> >    MessageBox.Show("WindowClosing Fired")
> >  End Sub
> >
> > The WindowClosing event is not fired and thus the messagebox is not
> > shown...
> >
> > Why and how do I fix this???
> >
> > "Chris Dunaway" wrote:
> >
> >> Chad wrote:
> >> > Hi
> >> >
> >> > In vb.net if you add a webbrowser control the windowclosing event does
> >> > not
> >> > fire. I have searched everywhere for a solution rather I get more
> >> > people
> >> > saying I have the same problem.
> >>
> >> I cannot duplicate your error using VB.Net 2005.   I dragged a
> >> WebBrowser control to the form.  I then added a FormClosing event.  The
> >> event fired normally when I closed the form.  Perhaps I am
> >> misunderstanding the problem.
> >>
> >> Can you post a short but complete program that illustrates the problem?
> >>
> >> Chris
> >>
> >>
>
>
>
Author
22 Aug 2006 7:27 AM
Cor Ligthert [MVP]
Chad,

I was misreading it, I was thinking VBNet 1.1 and VBNet 2.0.
It seems that I keep reading this when it is about the webbrowser.

I tested it, and got the same result as you.

It is for me however now impossible to find any reasonable information about
the axwebbrowser on MSDN because of the change to the search engine from
MSN.

Sorry that I cannot help you, I have not enough information anymore for
that.

Cor

Show quoteHide quote
"Chad" <C***@discussions.microsoft.com> schreef in bericht
news:9E5E4CB9-6BE5-4B3B-BE2B-BCD73EF24A7C@microsoft.com...
> Hi Cor
>
> Sorry, I dont understand what you mean...
>
> VB6 works VB.NET does not work.
>
> Please try the examples.
>
> If there is no work around does VS.NET 2005 offer any hope???
>
> Regards
> Chad
>
> "Cor Ligthert [MVP]" wrote:
>
>> Chad,
>>
>> I assume that your samples are a little bit mixed up, however.
>>
>> The events in the 2.0 webbrowser are very very very much inferior to the
>> ones in the AxWebbrowser. As Herfried ones showed is it possible to
>> create
>> workarounds for those. I don't know a workaround for this one.
>>
>> Maybe if there are no returned documents.
>>
>> Cor
>>
>> "Chad" <C***@discussions.microsoft.com> schreef in bericht
>> news:1F5FAF74-72F7-4D26-B958-452B9F823CBC@microsoft.com...
>> > Thanks Chris
>> >
>> > I should of been more detailed.
>> >
>> > If you access a html page with java script to close the form the
>> > windowclosing event is not fired through the webbrowser. It works in
>> > VB6
>> > but
>> > not VB.NET which is very annoying.
>> >
>> > I have set up an example for you, add the code and click on the close
>> > button.
>> >
>> > In vb6
>> > Add the webbrowser control and this code...
>> > Private Sub Form_Load()
>> >  WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
>> > End Sub
>> >
>> > Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,
>> > Cancel
>> > As Boolean)
>> >  MsgBox "WindowClosing Fired"
>> > End Sub
>> >
>> > Now in VB.NET add the webbrowser and this code
>> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> > System.EventArgs) Handles MyBase.Load
>> >    AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
>> >  End Sub
>> >
>> >  Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal
>> > e
>> > As
>> > AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
>> > AxWebBrowser1.WindowClosing
>> >    MessageBox.Show("WindowClosing Fired")
>> >  End Sub
>> >
>> > The WindowClosing event is not fired and thus the messagebox is not
>> > shown...
>> >
>> > Why and how do I fix this???
>> >
>> > "Chris Dunaway" wrote:
>> >
>> >> Chad wrote:
>> >> > Hi
>> >> >
>> >> > In vb.net if you add a webbrowser control the windowclosing event
>> >> > does
>> >> > not
>> >> > fire. I have searched everywhere for a solution rather I get more
>> >> > people
>> >> > saying I have the same problem.
>> >>
>> >> I cannot duplicate your error using VB.Net 2005.   I dragged a
>> >> WebBrowser control to the form.  I then added a FormClosing event.
>> >> The
>> >> event fired normally when I closed the form.  Perhaps I am
>> >> misunderstanding the problem.
>> >>
>> >> Can you post a short but complete program that illustrates the
>> >> problem?
>> >>
>> >> Chris
>> >>
>> >>
>>
>>
>>
Author
22 Aug 2006 12:45 PM
Chris Dunaway
Chad wrote:
> Sorry, I dont understand what you mean...
>

He means that the WebBrowser control that is included with VB2005 is
different than the one you are using.  When I dragged one to the form,
there was no WindowClosing event nor could I find one that was similar.
Author
22 Aug 2006 12:59 PM
Cor Ligthert [MVP]
In addition to Chris, I tested your sample with VB 2003 and had the same
problem as you.

This does not help, but as I was keen to find information on MSDN, that is
now only giving two articles not giving any information about the
axwebbrowser.

Cor

Show quoteHide quote
"Chad" <C***@discussions.microsoft.com> schreef in bericht
news:9E5E4CB9-6BE5-4B3B-BE2B-BCD73EF24A7C@microsoft.com...
> Hi Cor
>
> Sorry, I dont understand what you mean...
>
> VB6 works VB.NET does not work.
>
> Please try the examples.
>
> If there is no work around does VS.NET 2005 offer any hope???
>
> Regards
> Chad
>
> "Cor Ligthert [MVP]" wrote:
>
>> Chad,
>>
>> I assume that your samples are a little bit mixed up, however.
>>
>> The events in the 2.0 webbrowser are very very very much inferior to the
>> ones in the AxWebbrowser. As Herfried ones showed is it possible to
>> create
>> workarounds for those. I don't know a workaround for this one.
>>
>> Maybe if there are no returned documents.
>>
>> Cor
>>
>> "Chad" <C***@discussions.microsoft.com> schreef in bericht
>> news:1F5FAF74-72F7-4D26-B958-452B9F823CBC@microsoft.com...
>> > Thanks Chris
>> >
>> > I should of been more detailed.
>> >
>> > If you access a html page with java script to close the form the
>> > windowclosing event is not fired through the webbrowser. It works in
>> > VB6
>> > but
>> > not VB.NET which is very annoying.
>> >
>> > I have set up an example for you, add the code and click on the close
>> > button.
>> >
>> > In vb6
>> > Add the webbrowser control and this code...
>> > Private Sub Form_Load()
>> >  WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
>> > End Sub
>> >
>> > Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,
>> > Cancel
>> > As Boolean)
>> >  MsgBox "WindowClosing Fired"
>> > End Sub
>> >
>> > Now in VB.NET add the webbrowser and this code
>> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> > System.EventArgs) Handles MyBase.Load
>> >    AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
>> >  End Sub
>> >
>> >  Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal
>> > e
>> > As
>> > AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
>> > AxWebBrowser1.WindowClosing
>> >    MessageBox.Show("WindowClosing Fired")
>> >  End Sub
>> >
>> > The WindowClosing event is not fired and thus the messagebox is not
>> > shown...
>> >
>> > Why and how do I fix this???
>> >
>> > "Chris Dunaway" wrote:
>> >
>> >> Chad wrote:
>> >> > Hi
>> >> >
>> >> > In vb.net if you add a webbrowser control the windowclosing event
>> >> > does
>> >> > not
>> >> > fire. I have searched everywhere for a solution rather I get more
>> >> > people
>> >> > saying I have the same problem.
>> >>
>> >> I cannot duplicate your error using VB.Net 2005.   I dragged a
>> >> WebBrowser control to the form.  I then added a FormClosing event.
>> >> The
>> >> event fired normally when I closed the form.  Perhaps I am
>> >> misunderstanding the problem.
>> >>
>> >> Can you post a short but complete program that illustrates the
>> >> problem?
>> >>
>> >> Chris
>> >>
>> >>
>>
>>
>>
Author
23 Aug 2006 12:17 AM
Chad
Hi Cor

Thanks for your help.

If I were to go down the line of 2005, which I will very soon. If there is
not a windowclosing event, is there a way to intercept if the java script has
closed so I can somehow also close the form down by using the example
provided.

That is what I am after, a way to detect if the java script me.close(or
equivalent) has been processed.

Regards
Chad

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> In addition to Chris, I tested your sample with VB 2003 and had the same
> problem as you.
>
> This does not help, but as I was keen to find information on MSDN, that is
> now only giving two articles not giving any information about the
> axwebbrowser.
>
> Cor
>
> "Chad" <C***@discussions.microsoft.com> schreef in bericht
> news:9E5E4CB9-6BE5-4B3B-BE2B-BCD73EF24A7C@microsoft.com...
> > Hi Cor
> >
> > Sorry, I dont understand what you mean...
> >
> > VB6 works VB.NET does not work.
> >
> > Please try the examples.
> >
> > If there is no work around does VS.NET 2005 offer any hope???
> >
> > Regards
> > Chad
> >
> > "Cor Ligthert [MVP]" wrote:
> >
> >> Chad,
> >>
> >> I assume that your samples are a little bit mixed up, however.
> >>
> >> The events in the 2.0 webbrowser are very very very much inferior to the
> >> ones in the AxWebbrowser. As Herfried ones showed is it possible to
> >> create
> >> workarounds for those. I don't know a workaround for this one.
> >>
> >> Maybe if there are no returned documents.
> >>
> >> Cor
> >>
> >> "Chad" <C***@discussions.microsoft.com> schreef in bericht
> >> news:1F5FAF74-72F7-4D26-B958-452B9F823CBC@microsoft.com...
> >> > Thanks Chris
> >> >
> >> > I should of been more detailed.
> >> >
> >> > If you access a html page with java script to close the form the
> >> > windowclosing event is not fired through the webbrowser. It works in
> >> > VB6
> >> > but
> >> > not VB.NET which is very annoying.
> >> >
> >> > I have set up an example for you, add the code and click on the close
> >> > button.
> >> >
> >> > In vb6
> >> > Add the webbrowser control and this code...
> >> > Private Sub Form_Load()
> >> >  WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
> >> > End Sub
> >> >
> >> > Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,
> >> > Cancel
> >> > As Boolean)
> >> >  MsgBox "WindowClosing Fired"
> >> > End Sub
> >> >
> >> > Now in VB.NET add the webbrowser and this code
> >> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> >> > System.EventArgs) Handles MyBase.Load
> >> >    AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
> >> >  End Sub
> >> >
> >> >  Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal
> >> > e
> >> > As
> >> > AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
> >> > AxWebBrowser1.WindowClosing
> >> >    MessageBox.Show("WindowClosing Fired")
> >> >  End Sub
> >> >
> >> > The WindowClosing event is not fired and thus the messagebox is not
> >> > shown...
> >> >
> >> > Why and how do I fix this???
> >> >
> >> > "Chris Dunaway" wrote:
> >> >
> >> >> Chad wrote:
> >> >> > Hi
> >> >> >
> >> >> > In vb.net if you add a webbrowser control the windowclosing event
> >> >> > does
> >> >> > not
> >> >> > fire. I have searched everywhere for a solution rather I get more
> >> >> > people
> >> >> > saying I have the same problem.
> >> >>
> >> >> I cannot duplicate your error using VB.Net 2005.   I dragged a
> >> >> WebBrowser control to the form.  I then added a FormClosing event.
> >> >> The
> >> >> event fired normally when I closed the form.  Perhaps I am
> >> >> misunderstanding the problem.
> >> >>
> >> >> Can you post a short but complete program that illustrates the
> >> >> problem?
> >> >>
> >> >> Chris
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
Author
23 Aug 2006 12:41 AM
Denis Voyer
Hi Chad

Try this:

Private Sub AxWebBrowser_BeforeNavigate2(ByVal sender As System.Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event) Handles AxWebBrowser.BeforeNavigate2

If e.uRL = "javascript:window.close();" Then
        Do something
End If

End Sub

Hope this helps :-)

Denis

Show quoteHide quote
"Chad" <C***@discussions.microsoft.com> wrote in message news:38728F96-F7AF-431A-A31E-7B63E40172F3@microsoft.com...
> Hi Cor
>
> Thanks for your help.
>
> If I were to go down the line of 2005, which I will very soon. If there is
> not a windowclosing event, is there a way to intercept if the java script has
> closed so I can somehow also close the form down by using the example
> provided.
>
> That is what I am after, a way to detect if the java script me.close(or
> equivalent) has been processed.
>
> Regards
> Chad
>
> "Cor Ligthert [MVP]" wrote:
>
>> In addition to Chris, I tested your sample with VB 2003 and had the same
>> problem as you.
>>
>> This does not help, but as I was keen to find information on MSDN, that is
>> now only giving two articles not giving any information about the
>> axwebbrowser.
>>
>> Cor
>>
>> "Chad" <C***@discussions.microsoft.com> schreef in bericht
>> news:9E5E4CB9-6BE5-4B3B-BE2B-BCD73EF24A7C@microsoft.com...
>> > Hi Cor
>> >
>> > Sorry, I dont understand what you mean...
>> >
>> > VB6 works VB.NET does not work.
>> >
>> > Please try the examples.
>> >
>> > If there is no work around does VS.NET 2005 offer any hope???
>> >
>> > Regards
>> > Chad
>> >
>> > "Cor Ligthert [MVP]" wrote:
>> >
>> >> Chad,
>> >>
>> >> I assume that your samples are a little bit mixed up, however.
>> >>
>> >> The events in the 2.0 webbrowser are very very very much inferior to the
>> >> ones in the AxWebbrowser. As Herfried ones showed is it possible to
>> >> create
>> >> workarounds for those. I don't know a workaround for this one.
>> >>
>> >> Maybe if there are no returned documents.
>> >>
>> >> Cor
>> >>
>> >> "Chad" <C***@discussions.microsoft.com> schreef in bericht
>> >> news:1F5FAF74-72F7-4D26-B958-452B9F823CBC@microsoft.com...
>> >> > Thanks Chris
>> >> >
>> >> > I should of been more detailed.
>> >> >
>> >> > If you access a html page with java script to close the form the
>> >> > windowclosing event is not fired through the webbrowser. It works in
>> >> > VB6
>> >> > but
>> >> > not VB.NET which is very annoying.
>> >> >
>> >> > I have set up an example for you, add the code and click on the close
>> >> > button.
>> >> >
>> >> > In vb6
>> >> > Add the webbrowser control and this code...
>> >> > Private Sub Form_Load()
>> >> >  WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
>> >> > End Sub
>> >> >
>> >> > Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,
>> >> > Cancel
>> >> > As Boolean)
>> >> >  MsgBox "WindowClosing Fired"
>> >> > End Sub
>> >> >
>> >> > Now in VB.NET add the webbrowser and this code
>> >> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> >> > System.EventArgs) Handles MyBase.Load
>> >> >    AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
>> >> >  End Sub
>> >> >
>> >> >  Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal
>> >> > e
>> >> > As
>> >> > AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
>> >> > AxWebBrowser1.WindowClosing
>> >> >    MessageBox.Show("WindowClosing Fired")
>> >> >  End Sub
>> >> >
>> >> > The WindowClosing event is not fired and thus the messagebox is not
>> >> > shown...
>> >> >
>> >> > Why and how do I fix this???
>> >> >
>> >> > "Chris Dunaway" wrote:
>> >> >
>> >> >> Chad wrote:
>> >> >> > Hi
>> >> >> >
>> >> >> > In vb.net if you add a webbrowser control the windowclosing event
>> >> >> > does
>> >> >> > not
>> >> >> > fire. I have searched everywhere for a solution rather I get more
>> >> >> > people
>> >> >> > saying I have the same problem.
>> >> >>
>> >> >> I cannot duplicate your error using VB.Net 2005.   I dragged a
>> >> >> WebBrowser control to the form.  I then added a FormClosing event.
>> >> >> The
>> >> >> event fired normally when I closed the form.  Perhaps I am
>> >> >> misunderstanding the problem.
>> >> >>
>> >> >> Can you post a short but complete program that illustrates the
>> >> >> problem?
>> >> >>
>> >> >> Chris
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>
Author
22 Aug 2006 11:39 AM
Andreas Mueller
Chad wrote:

Show quoteHide quote
> Hi
>
> In vb.net if you add a webbrowser control the windowclosing event does not
> fire. I have searched everywhere for a solution rather I get more people
> saying I have the same problem.
>
> I found this...Could someone please convert this to VB.NET to give us a
> glimmer of hope OR provide a solution.
>
> If u implement axWebBrowser, you'll find the WindowClosing event doesn't
> fire. This is the work around, which I confirm works.
>
> 1. Right below the System.Windows.Forms.Form class add another class
> whichderives from SHDocVw.DWebBrowserEvents2. For example:\
>
> public class IEEvents: SHDocVw.DWebBrowserEvents2
> {}
>
> 2. Save the file and go to class view (View | Class View menu option). Go to
> IEEvents class in the tree view and expand it. Keep expanding its children
> till you see 'DWebBrowserEvents'. Right click and select 'Add | Implement
> interfaces' menu option.
>
> 3. A method for WindowClosing event should be generated by above step. Apply
> the 'DispId' attribute to the method as shown below:
>
> [DispId(0x00000107)]
> public void WindowClosing(bool IsChildWindow, ref bool Cancel)
> {
> //message box to the event handler works
>    MessageBox.Show("Closing Event", "IE", MessageBoxButtons.OK,
> MessageBoxIcon.Exclamation);
> }
>
> 4. Add the following lines of code to the end of the Forms
> 'InitializeComponent' method.
>
> UCOMIConnectionPointContainer pConPtCon =
> (UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
> UCOMIConnectionPoint pConPt;
> Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
> pConPtCon.FindConnectionPoint(ref guid, out pConPt);
> IEEvents e = new IEEvents();
> //make sure you declare private int dwCookie in the form class but outside
> this method
> pConPt.Advise(e, out dwCookie);
>
> 5. Add the following lines of code to the beginning of the Forms Close
> handler method.
>
> UCOMIConnectionPointContainer pConPtCon =
> (UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
> UCOMIConnectionPoint pConPt;
> Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
> pConPtCon.FindConnectionPoint(ref guid, out pConPt);
> pConPt.Unadvise(dwCookie);
>
> URL:http://www.kbcafe.com/iBLOGthere4iM/?guid=20040501150250
>
> Thank-you and regards
> Chad

Here's tthe code in VB.Net:

Option Explicit On
Option Strict On

Imports System.Runtime.InteropServices

Public Class Form1
     Inherits System.Windows.Forms.Form


     Public Sub New()
         MyBase.New()

         'This call is required by the Windows Form Designer.
         InitializeComponent()

         'Add any initialization after the InitializeComponent() call

         Dim pConPtCon As UCOMIConnectionPointContainer =
CType(Me.AxWebBrowser1.GetOcx(), UCOMIConnectionPointContainer)
         Dim pConPt As UCOMIConnectionPoint
         Dim guid As Guid = GetType(SHDocVw.DWebBrowserEvents2).GUID
         pConPtCon.FindConnectionPoint(guid, pConPt)
         Dim ieEvent As New WebBrowserEvents
         pConPt.Advise(ieEvent, dwCookie)

     End Sub

     Dim dwCookie As Integer = -1

#Region " Windows Form Designer generated code "

     'Form overrides dispose to clean up the component list.
     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
         If disposing Then
             If Not (components Is Nothing) Then
                 components.Dispose()
             End If
         End If
         MyBase.Dispose(disposing)
     End Sub

     'Required by the Windows Form Designer
     Private components As System.ComponentModel.IContainer

     'NOTE: The following procedure is required by the Windows Form Designer
     'It can be modified using the Windows Form Designer.
     'Do not modify it using the code editor.
     Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
     Friend WithEvents Button1 As System.Windows.Forms.Button
     <System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
         Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Form1))
         Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
         Me.Button1 = New System.Windows.Forms.Button
         CType(Me.AxWebBrowser1,
System.ComponentModel.ISupportInitialize).BeginInit()
         Me.SuspendLayout()
         '
         'AxWebBrowser1
         '
         Me.AxWebBrowser1.Enabled = True
         Me.AxWebBrowser1.Location = New System.Drawing.Point(24, 24)
         Me.AxWebBrowser1.OcxState =
CType(resources.GetObject("AxWebBrowser1.OcxState"),
System.Windows.Forms.AxHost.State)
         Me.AxWebBrowser1.Size = New System.Drawing.Size(300, 150)
         Me.AxWebBrowser1.TabIndex = 0
         '
         'Button1
         '
         Me.Button1.Location = New System.Drawing.Point(96, 216)
         Me.Button1.Name = "Button1"
         Me.Button1.TabIndex = 1
         Me.Button1.Text = "Close Ax"
         '
         'Form1
         '
         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
         Me.ClientSize = New System.Drawing.Size(360, 286)
         Me.Controls.Add(Me.Button1)
         Me.Controls.Add(Me.AxWebBrowser1)
         Me.Name = "Form1"
         Me.Text = "Form1"
         CType(Me.AxWebBrowser1,
System.ComponentModel.ISupportInitialize).EndInit()
         Me.ResumeLayout(False)

     End Sub

#End Region

     Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
         Dim pConPtCon As UCOMIConnectionPointContainer =
CType(Me.AxWebBrowser1.GetOcx(), UCOMIConnectionPointContainer)
         Dim pConPt As UCOMIConnectionPoint
         Dim guid As Guid = GetType(SHDocVw.DWebBrowserEvents2).GUID
         pConPtCon.FindConnectionPoint(guid, pConPt)
         Dim ieEvent As New WebBrowserEvents
         pConPt.Unadvise(dwCookie)
     End Sub
End Class

Class WebBrowserEvents
     Implements SHDocVw.DWebBrowserEvents2

     <DispId(263)> _
         Public Sub WindowClosing(ByVal IsChildWindow As Boolean, ByRef
Cancel As Boolean) Implements SHDocVw.DWebBrowserEvents2.WindowClosing
         MessageBox.Show("IE is closing!")
     End Sub

     Public Sub BeforeNavigate2(ByVal pDisp As Object, ByRef URL As
Object, ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef
PostData As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
Implements SHDocVw.DWebBrowserEvents2.BeforeNavigate2

     End Sub

     Public Sub ClientToHostWindow(ByRef CX As Integer, ByRef CY As
Integer) Implements SHDocVw.DWebBrowserEvents2.ClientToHostWindow

     End Sub

     Public Sub CommandStateChange(ByVal Command As Integer, ByVal
Enable As Boolean) Implements SHDocVw.DWebBrowserEvents2.CommandStateChange

     End Sub

     Public Sub DocumentComplete(ByVal pDisp As Object, ByRef URL As
Object) Implements SHDocVw.DWebBrowserEvents2.DocumentComplete

     End Sub

     Public Sub DownloadBegin() Implements
SHDocVw.DWebBrowserEvents2.DownloadBegin

     End Sub

     Public Sub DownloadComplete() Implements
SHDocVw.DWebBrowserEvents2.DownloadComplete

     End Sub

     Public Sub FileDownload(ByRef Cancel As Boolean) Implements
SHDocVw.DWebBrowserEvents2.FileDownload

     End Sub

     Public Sub NavigateComplete2(ByVal pDisp As Object, ByRef URL As
Object) Implements SHDocVw.DWebBrowserEvents2.NavigateComplete2

     End Sub

     Public Sub NavigateError(ByVal pDisp As Object, ByRef URL As
Object, ByRef Frame As Object, ByRef StatusCode As Object, ByRef Cancel
As Boolean) Implements SHDocVw.DWebBrowserEvents2.NavigateError

     End Sub

     Public Sub NewWindow2(ByRef ppDisp As Object, ByRef Cancel As
Boolean) Implements SHDocVw.DWebBrowserEvents2.NewWindow2

     End Sub

     Public Sub NewWindow3(ByRef ppDisp As Object, ByRef Cancel As
Boolean, ByVal dwFlags As System.UInt32, ByVal bstrUrlContext As String,
ByVal bstrUrl As String) Implements SHDocVw.DWebBrowserEvents2.NewWindow3

     End Sub

     Public Sub OnFullScreen(ByVal FullScreen As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnFullScreen

     End Sub

     Public Sub OnMenuBar(ByVal MenuBar As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnMenuBar

     End Sub

     Public Sub OnQuit() Implements SHDocVw.DWebBrowserEvents2.OnQuit

     End Sub

     Public Sub OnStatusBar(ByVal StatusBar As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnStatusBar

     End Sub

     Public Sub OnTheaterMode(ByVal TheaterMode As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnTheaterMode

     End Sub

     Public Sub OnToolBar(ByVal ToolBar As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnToolBar

     End Sub

     Public Sub OnVisible(ByVal Visible As Boolean) Implements
SHDocVw.DWebBrowserEvents2.OnVisible

     End Sub

     Public Sub PrintTemplateInstantiation(ByVal pDisp As Object)
Implements SHDocVw.DWebBrowserEvents2.PrintTemplateInstantiation

     End Sub

     Public Sub PrintTemplateTeardown(ByVal pDisp As Object) Implements
SHDocVw.DWebBrowserEvents2.PrintTemplateTeardown

     End Sub

     Public Sub PrivacyImpactedStateChange(ByVal bImpacted As Boolean)
Implements SHDocVw.DWebBrowserEvents2.PrivacyImpactedStateChange

     End Sub

     Public Sub ProgressChange(ByVal Progress As Integer, ByVal
ProgressMax As Integer) Implements SHDocVw.DWebBrowserEvents2.ProgressChange

     End Sub

     Public Sub PropertyChange(ByVal szProperty As String) Implements
SHDocVw.DWebBrowserEvents2.PropertyChange

     End Sub

     Public Sub SetSecureLockIcon(ByVal SecureLockIcon As Integer)
Implements SHDocVw.DWebBrowserEvents2.SetSecureLockIcon

     End Sub

     Public Sub StatusTextChange(ByVal Text As String) Implements
SHDocVw.DWebBrowserEvents2.StatusTextChange

     End Sub

     Public Sub TitleChange(ByVal Text As String) Implements
SHDocVw.DWebBrowserEvents2.TitleChange

     End Sub

     Public Sub UpdatePageStatus(ByVal pDisp As Object, ByRef nPage As
Object, ByRef fDone As Object) Implements
SHDocVw.DWebBrowserEvents2.UpdatePageStatus

     End Sub

     Public Sub WindowSetHeight(ByVal Height As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetHeight

     End Sub

     Public Sub WindowSetLeft(ByVal Left As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetLeft

     End Sub

     Public Sub WindowSetResizable(ByVal Resizable As Boolean)
Implements SHDocVw.DWebBrowserEvents2.WindowSetResizable

     End Sub

     Public Sub WindowSetTop(ByVal Top As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetTop

     End Sub

     Public Sub WindowSetWidth(ByVal Width As Integer) Implements
SHDocVw.DWebBrowserEvents2.WindowSetWidth

     End Sub
End Class


--
You can email me directly by removing the NOSPAm below
xmenNOSPAm40@gmxNOSPAm.netNOSPAm
Author
23 Aug 2006 12:13 AM
Chad
Hi Andreas

Thanks for your time, I feverishly got this up and going although this did
not work.

Still not firing...Im going to go down the line of upgrading to 2005 and try
my luck.

Thanks and regards
Chad

Show quoteHide quote
"Andreas Mueller" wrote:

> Chad wrote:
>
> > Hi
> >
> > In vb.net if you add a webbrowser control the windowclosing event does not
> > fire. I have searched everywhere for a solution rather I get more people
> > saying I have the same problem.
> >
> > I found this...Could someone please convert this to VB.NET to give us a
> > glimmer of hope OR provide a solution.
> >
> > If u implement axWebBrowser, you'll find the WindowClosing event doesn't
> > fire. This is the work around, which I confirm works.
> >
> > 1. Right below the System.Windows.Forms.Form class add another class
> > whichderives from SHDocVw.DWebBrowserEvents2. For example:\
> >
> > public class IEEvents: SHDocVw.DWebBrowserEvents2
> > {}
> >
> > 2. Save the file and go to class view (View | Class View menu option). Go to
> > IEEvents class in the tree view and expand it. Keep expanding its children
> > till you see 'DWebBrowserEvents'. Right click and select 'Add | Implement
> > interfaces' menu option.
> >
> > 3. A method for WindowClosing event should be generated by above step. Apply
> > the 'DispId' attribute to the method as shown below:
> >
> > [DispId(0x00000107)]
> > public void WindowClosing(bool IsChildWindow, ref bool Cancel)
> > {
> > //message box to the event handler works
> >    MessageBox.Show("Closing Event", "IE", MessageBoxButtons.OK,
> > MessageBoxIcon.Exclamation);
> > }
> >
> > 4. Add the following lines of code to the end of the Forms
> > 'InitializeComponent' method.
> >
> > UCOMIConnectionPointContainer pConPtCon =
> > (UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
> > UCOMIConnectionPoint pConPt;
> > Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
> > pConPtCon.FindConnectionPoint(ref guid, out pConPt);
> > IEEvents e = new IEEvents();
> > //make sure you declare private int dwCookie in the form class but outside
> > this method
> > pConPt.Advise(e, out dwCookie);
> >
> > 5. Add the following lines of code to the beginning of the Forms Close
> > handler method.
> >
> > UCOMIConnectionPointContainer pConPtCon =
> > (UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
> > UCOMIConnectionPoint pConPt;
> > Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
> > pConPtCon.FindConnectionPoint(ref guid, out pConPt);
> > pConPt.Unadvise(dwCookie);
> >
> > URL:http://www.kbcafe.com/iBLOGthere4iM/?guid=20040501150250
> >
> > Thank-you and regards
> > Chad
>
> Here's tthe code in VB.Net:
>
> Option Explicit On
> Option Strict On
>
> Imports System.Runtime.InteropServices
>
> Public Class Form1
>      Inherits System.Windows.Forms.Form
>
>
>      Public Sub New()
>          MyBase.New()
>
>          'This call is required by the Windows Form Designer.
>          InitializeComponent()
>
>          'Add any initialization after the InitializeComponent() call
>
>          Dim pConPtCon As UCOMIConnectionPointContainer =
> CType(Me.AxWebBrowser1.GetOcx(), UCOMIConnectionPointContainer)
>          Dim pConPt As UCOMIConnectionPoint
>          Dim guid As Guid = GetType(SHDocVw.DWebBrowserEvents2).GUID
>          pConPtCon.FindConnectionPoint(guid, pConPt)
>          Dim ieEvent As New WebBrowserEvents
>          pConPt.Advise(ieEvent, dwCookie)
>
>      End Sub
>
>      Dim dwCookie As Integer = -1
>
> #Region " Windows Form Designer generated code "
>
>      'Form overrides dispose to clean up the component list.
>      Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>          If disposing Then
>              If Not (components Is Nothing) Then
>                  components.Dispose()
>              End If
>          End If
>          MyBase.Dispose(disposing)
>      End Sub
>
>      'Required by the Windows Form Designer
>      Private components As System.ComponentModel.IContainer
>
>      'NOTE: The following procedure is required by the Windows Form Designer
>      'It can be modified using the Windows Form Designer.
>      'Do not modify it using the code editor.
>      Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
>      Friend WithEvents Button1 As System.Windows.Forms.Button
>      <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>          Dim resources As System.Resources.ResourceManager = New
> System.Resources.ResourceManager(GetType(Form1))
>          Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
>          Me.Button1 = New System.Windows.Forms.Button
>          CType(Me.AxWebBrowser1,
> System.ComponentModel.ISupportInitialize).BeginInit()
>          Me.SuspendLayout()
>          '
>          'AxWebBrowser1
>          '
>          Me.AxWebBrowser1.Enabled = True
>          Me.AxWebBrowser1.Location = New System.Drawing.Point(24, 24)
>          Me.AxWebBrowser1.OcxState =
> CType(resources.GetObject("AxWebBrowser1.OcxState"),
> System.Windows.Forms.AxHost.State)
>          Me.AxWebBrowser1.Size = New System.Drawing.Size(300, 150)
>          Me.AxWebBrowser1.TabIndex = 0
>          '
>          'Button1
>          '
>          Me.Button1.Location = New System.Drawing.Point(96, 216)
>          Me.Button1.Name = "Button1"
>          Me.Button1.TabIndex = 1
>          Me.Button1.Text = "Close Ax"
>          '
>          'Form1
>          '
>          Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
>          Me.ClientSize = New System.Drawing.Size(360, 286)
>          Me.Controls.Add(Me.Button1)
>          Me.Controls.Add(Me.AxWebBrowser1)
>          Me.Name = "Form1"
>          Me.Text = "Form1"
>          CType(Me.AxWebBrowser1,
> System.ComponentModel.ISupportInitialize).EndInit()
>          Me.ResumeLayout(False)
>
>      End Sub
>
> #End Region
>
>      Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
>          Dim pConPtCon As UCOMIConnectionPointContainer =
> CType(Me.AxWebBrowser1.GetOcx(), UCOMIConnectionPointContainer)
>          Dim pConPt As UCOMIConnectionPoint
>          Dim guid As Guid = GetType(SHDocVw.DWebBrowserEvents2).GUID
>          pConPtCon.FindConnectionPoint(guid, pConPt)
>          Dim ieEvent As New WebBrowserEvents
>          pConPt.Unadvise(dwCookie)
>      End Sub
> End Class
>
> Class WebBrowserEvents
>      Implements SHDocVw.DWebBrowserEvents2
>
>      <DispId(263)> _
>          Public Sub WindowClosing(ByVal IsChildWindow As Boolean, ByRef
> Cancel As Boolean) Implements SHDocVw.DWebBrowserEvents2.WindowClosing
>          MessageBox.Show("IE is closing!")
>      End Sub
>
>      Public Sub BeforeNavigate2(ByVal pDisp As Object, ByRef URL As
> Object, ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef
> PostData As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
> Implements SHDocVw.DWebBrowserEvents2.BeforeNavigate2
>
>      End Sub
>
>      Public Sub ClientToHostWindow(ByRef CX As Integer, ByRef CY As
> Integer) Implements SHDocVw.DWebBrowserEvents2.ClientToHostWindow
>
>      End Sub
>
>      Public Sub CommandStateChange(ByVal Command As Integer, ByVal
> Enable As Boolean) Implements SHDocVw.DWebBrowserEvents2.CommandStateChange
>
>      End Sub
>
>      Public Sub DocumentComplete(ByVal pDisp As Object, ByRef URL As
> Object) Implements SHDocVw.DWebBrowserEvents2.DocumentComplete
>
>      End Sub
>
>      Public Sub DownloadBegin() Implements
> SHDocVw.DWebBrowserEvents2.DownloadBegin
>
>      End Sub
>
>      Public Sub DownloadComplete() Implements
> SHDocVw.DWebBrowserEvents2.DownloadComplete
>
>      End Sub
>
>      Public Sub FileDownload(ByRef Cancel As Boolean) Implements
> SHDocVw.DWebBrowserEvents2.FileDownload
>
>      End Sub
>
>      Public Sub NavigateComplete2(ByVal pDisp As Object, ByRef URL As
> Object) Implements SHDocVw.DWebBrowserEvents2.NavigateComplete2
>
>      End Sub
>
>      Public Sub NavigateError(ByVal pDisp As Object, ByRef URL As
> Object, ByRef Frame As Object, ByRef StatusCode As Object, ByRef Cancel
> As Boolean) Implements SHDocVw.DWebBrowserEvents2.NavigateError
>
>      End Sub
>
>      Public Sub NewWindow2(ByRef ppDisp As Object, ByRef Cancel As
> Boolean) Implements SHDocVw.DWebBrowserEvents2.NewWindow2
>
>      End Sub
>
>      Public Sub NewWindow3(ByRef ppDisp As Object, ByRef Cancel As
> Boolean, ByVal dwFlags As System.UInt32, ByVal bstrUrlContext As String,
> ByVal bstrUrl As String) Implements SHDocVw.DWebBrowserEvents2.NewWindow3
>
>      End Sub
>
>      Public Sub OnFullScreen(ByVal FullScreen As Boolean) Implements
> SHDocVw.DWebBrowserEvents2.OnFullScreen
>
>      End Sub
>
>      Public Sub OnMenuBar(ByVal MenuBar As Boolean) Implements
> SHDocVw.DWebBrowserEvents2.OnMenuBar
>
>      End Sub
>
>      Public Sub OnQuit() Implements SHDocVw.DWebBrowserEvents2.OnQuit
>
>      End Sub
>
>      Public Sub OnStatusBar(ByVal StatusBar As Boolean) Implements
> SHDocVw.DWebBrowserEvents2.OnStatusBar
>
>      End Sub
>
>      Public Sub OnTheaterMode(ByVal TheaterMode As Boolean) Implements
> SHDocVw.DWebBrowserEvents2.OnTheaterMode
>
>      End Sub
>
>      Public Sub OnToolBar(ByVal ToolBar As Boolean) Implements
> SHDocVw.DWebBrowserEvents2.OnToolBar
>
>      End Sub
>
>      Public Sub OnVisible(ByVal Visible As Boolean) Implements
> SHDocVw.DWebBrowserEvents2.OnVisible
>
>      End Sub
>
>      Public Sub PrintTemplateInstantiation(ByVal pDisp As Object)
> Implements SHDocVw.DWebBrowserEvents2.PrintTemplateInstantiation
>
>      End Sub
>
>      Public Sub PrintTemplateTeardown(ByVal pDisp As Object) Implements
> SHDocVw.DWebBrowserEvents2.PrintTemplateTeardown
>
>      End Sub
>
>      Public Sub PrivacyImpactedStateChange(ByVal bImpacted As Boolean)
> Implements SHDocVw.DWebBrowserEvents2.PrivacyImpactedStateChange
>
>      End Sub
>
>      Public Sub ProgressChange(ByVal Progress As Integer, ByVal
> ProgressMax As Integer) Implements SHDocVw.DWebBrowserEvents2.ProgressChange
>
>      End Sub
>
>      Public Sub PropertyChange(ByVal szProperty As String) Implements
> SHDocVw.DWebBrowserEvents2.PropertyChange
>
>      End Sub
>
>      Public Sub SetSecureLockIcon(ByVal SecureLockIcon As Integer)
> Implements SHDocVw.DWebBrowserEvents2.SetSecureLockIcon
>
>      End Sub
Author
23 Aug 2006 3:00 AM
Chad
Thank-you all for your comments.

I will use the example from Denis as a workaround.

Private Sub AxWebBrowser1_BeforeNavigate2(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event) Handles
AxWebBrowser1.BeforeNavigate2
    If mLastPageShown Then
      Me.Close() ' Closes form from java script
    End If
  End Sub

Regards
Chad

Show quoteHide quote
"Chad" wrote:

> Hi
>
> In vb.net if you add a webbrowser control the windowclosing event does not
> fire. I have searched everywhere for a solution rather I get more people
> saying I have the same problem.
>
> I found this...Could someone please convert this to VB.NET to give us a
> glimmer of hope OR provide a solution.
>
> If u implement axWebBrowser, you'll find the WindowClosing event doesn't
> fire. This is the work around, which I confirm works.
>
> 1. Right below the System.Windows.Forms.Form class add another class
> whichderives from SHDocVw.DWebBrowserEvents2. For example:\
>
> public class IEEvents: SHDocVw.DWebBrowserEvents2
> {}
>
> 2. Save the file and go to class view (View | Class View menu option). Go to
> IEEvents class in the tree view and expand it. Keep expanding its children
> till you see 'DWebBrowserEvents'. Right click and select 'Add | Implement
> interfaces' menu option.
>
> 3. A method for WindowClosing event should be generated by above step. Apply
> the 'DispId' attribute to the method as shown below:
>
> [DispId(0x00000107)]
> public void WindowClosing(bool IsChildWindow, ref bool Cancel)
> {
> //message box to the event handler works
>    MessageBox.Show("Closing Event", "IE", MessageBoxButtons.OK,
> MessageBoxIcon.Exclamation);
> }
>
> 4. Add the following lines of code to the end of the Forms
> 'InitializeComponent' method.
>
> UCOMIConnectionPointContainer pConPtCon =
> (UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
> UCOMIConnectionPoint pConPt;
> Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
> pConPtCon.FindConnectionPoint(ref guid, out pConPt);
> IEEvents e = new IEEvents();
> //make sure you declare private int dwCookie in the form class but outside
> this method
> pConPt.Advise(e, out dwCookie);
>
> 5. Add the following lines of code to the beginning of the Forms Close
> handler method.
>
> UCOMIConnectionPointContainer pConPtCon =
> (UCOMIConnectionPointContainer)this.axWebBrowser1.GetOcx();
> UCOMIConnectionPoint pConPt;
> Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
> pConPtCon.FindConnectionPoint(ref guid, out pConPt);
> pConPt.Unadvise(dwCookie);
>
> URL:http://www.kbcafe.com/iBLOGthere4iM/?guid=20040501150250
>
> Thank-you and regards
> Chad