如何滚动到System.Windows.Forms.WebBrowser的结尾?

Bil*_*rty 5 .net browser

如何以编程方式滚动到System.Windows.Forms.WebBrowser的末尾?

Tar*_*ier 15

ctlWebBrowser.Document.Body.ScrollIntoView(false);
Run Code Online (Sandbox Code Playgroud)

ScrollIntoView()的布尔参数为true以使滚动条与文档顶部对齐,false为将滚动条与文档底部对齐.

这里的MSDN文档:HtmlElement.ScrollIntoView

  • 但请记住,加载到`WebBrowser`中的HTML需要包含`Body`标记.如果你想在内容加载到`WebBrowser`实例后立即执行,最好使用`Navigated`事件,例如:webBrowser1.Navigated + =(s1,e1)=> {if(webBrowser1) .Document.Body!= null)webBrowser1.Document.Body.ScrollIntoView(false); }; (3认同)

ycl*_*vnc 12

我正在设置控件的DocumentText属性WebBrowser(使用html和body标签),Document.Body.ScrollIntoView(false)方法对我不起作用,但这是有效的:

    private void ScrollToBottom()
    {
        // MOST IMP : processes all windows messages queue
        Application.DoEvents();

        if (webBrowser1.Document != null)
        {
            webBrowser1.Document.Window.ScrollTo(0, webBrowser1.Document.Body.ScrollRectangle.Height);
        }
    }
Run Code Online (Sandbox Code Playgroud)

来源:http://kiranpatils.wordpress.com/2010/07/19/webbrowsercontrol-scroll-to-bottom/