views:

1509

answers:

2

I am trying to get the Y scroll index for a web page in the WebBrowser control but I can't access the values for the built in Scroll bar.

Any Ideas?

+2  A: 

For IE in standards mode (with a doctype, as you say) scrollTop is a property of the <html> element, not the <body>:

HtmlDocument htmlDoc = this.webBrowser1.Document;
int scrollTop = htmlDoc.GetElementsByTagName("HTML")[0].ScrollTop;

(A nicer way to get to the <html> element would be good, if anyone knows of one.)

RichieHindle
HtmlDocument doesnt have a documentElement property according to VS :S are you using a different library?
I'm using COM via C++, and accessing documentElement via IHTMLDocument3. Not much use in C#! 8-) I've changed my answer to give tested C# code - sorry about that, I should have tested it the first time.
RichieHindle
thanks that works a treat!
A: 

are you trying to target an HTML element to bring it into view? If that is what you are after you can do this...

htmlDoc.GetElementById("tag_id_string_goes_here").ScrollIntoView(true);

true aligns it with the top and false with the bottom of the element. You can also use ScrollRectangle to get the dimensions of the scrollable region.