getting the scroll value from a WebBrowser Control C#

萝らか妹 提交于 2019-12-06 04:13:12

问题


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?


回答1:


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.)




回答2:


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.




回答3:


WebBrowser1.Document.Body.ScrollTop;
WebBrowser1.Document.Body.ScrollRectangle.Height;


来源:https://stackoverflow.com/questions/785792/getting-the-scroll-value-from-a-webbrowser-control-c-sharp

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