getting the scroll value from a WebBrowser Control C#

混江龙づ霸主 提交于 2019-12-04 11:41:38

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.

Rich
WebBrowser1.Document.Body.ScrollTop;
WebBrowser1.Document.Body.ScrollRectangle.Height;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!