handling onscroll event of WebBrowser

J

Jocker

Hi Group
I'm writing an Internet Explorer plugin. Everything works well, except
when I try to handle the onscroll event.
From MSDN it seems that IHTMLWindow2.onscroll property is the way to go
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/window2/onscroll.asp
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onscroll.asp
another possibility seems to exist with IHTMLElement2.onscroll using
the document body, but this does not solve the problem.

the following code snippet compiles but when executed it always throws
a System.NotImplementedException
this is the stack trace:
in mshtml.HTMLWindow2Class.IHTMLWindow2_set_onscroll(Object p)

this is the code:
-------
//WebBrowser is a valid instance of SHDocVw.WebBrowserClass
this.WebBrowser.DocumentComplete += new
DWebBrowserEvents2_DocumentCompleteEventHandler(webBrowser_DocumentComplete);

void webBrowser_DocumentComplete(object pDisp, ref object URL)
{
mshtml.IHTMLDocument2 document =
(mshtml.IHTMLDocument2)this.WebBrowser.Document;
mshtml.IHTMLWindow2 window = document.parentWindow;

try
{
//window.onscroll =
// new mshtml.HTMLWindowEvents_onscrollEventHandler(
// this.webBrowserWindow_onscroll);
window.onscroll =
new mshtml.HTMLWindowEvents2_onscrollEventHandler(
this.webBrowserWindow_onscroll);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void webBrowserWindow_onscroll()
{
MessageBox.Show("scroll");
}
private void webBrowserWindow_onscroll(mshtml.IHTMLEventObj pEvtObj)
{
MessageBox.Show("scroll2");
}
 

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

Similar Threads


Top