简体   繁体   English

从WebBrowser控件C#获取滚动值

[英]getting the scroll value from a WebBrowser Control C#

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. 我试图在WebBrowser控件中获取网页的Y滚动索引,但我无法访问内置滚动条的值。

Any Ideas? 有任何想法吗?

For IE in standards mode (with a doctype, as you say) scrollTop is a property of the <html> element, not the <body> : 对于标准模式下的IE(如你所说的,带有doctype), scrollTop<html>元素的属性,而不是<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.) (一个更好的方法来获取<html>元素会很好,如果有人知道的话。)

are you trying to target an HTML element to bring it into view? 您是否尝试将HTML元素作为目标进行查看? If that is what you are after you can do this... 如果你能做到这一点就是这样......

htmlDoc.GetElementById("tag_id_string_goes_here").ScrollIntoView(true); htmlDoc.GetElementById( “tag_id_string_goes_here”)ScrollIntoView(真)。

true aligns it with the top and false with the bottom of the element. true将其与top对齐,false与元素的底部对齐。 You can also use ScrollRectangle to get the dimensions of the scrollable region. 您还可以使用ScrollRectangle来获取可滚动区域的尺寸。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM