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?
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?
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.)
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.
WebBrowser1.Document.Body.ScrollTop;
WebBrowser1.Document.Body.ScrollRectangle.Height;