Capturing AxWebBrowser events

  • Thread starter Thread starter PontiMax
  • Start date Start date
P

PontiMax

My WinForm application hosts an AxWebBrowser control to
display HTML help files. Now I'm trying to capture all
mouse click events so that I can take the right steps if
the user clicks a certain hyperlink element.

I have followed the instructions from Microsoft
(http://support.microsoft.com/?kbid=312777) to accomplish
this but what happens is, if I add the onClick event
handler the browser becomes (partly) disabled: the context
menu doesn't work any more, the same holds for the
scrollbar (wheel functionality is disabled), I'm not able
to select text, etc.

Is there a problem with my code (see below)? Or is there a
better solution to this?

// Customize AxWebBrowser control
....
this.webBrowser.DocumentComplete += new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler
(this.WebBrowser_DocumentComplete);
....

private void WebBrowser_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
mshtml.HTMLDocument oHTMLDocument;
oHTMLDocument = (mshtml.HTMLDocument)
this.webBrowser.Document;
mshtml.HTMLDocumentEvents2_Event oEvent;
oEvent = (mshtml.HTMLDocumentEvents2_Event) oHTMLDocument;
oEvent.onclick += new
mshtml.HTMLDocumentEvents2_onclickEventHandler(
this.ClickEventHandler);
}

private bool ClickEventHandler(mshtml.IHTMLEventObj e)
{
Debug.WriteLine("Clicked on "+ e.srcElement.tagName);
return true;
}

Thank you very much for your help!
 
The only way to work this is to inherit from the base class/interface and
impliment stubs for each event in the interface.

If you have Vs.net 2003 you'll be treated to the whole thing being done for
you, if not you have to do them manually.

Implimenting the events themselves causes the control to freak out and die
as you describe.

James Hancock
 
Back
Top