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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/990651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:51:51  来源:igfitidea点击:

How to scroll to end of System.Windows.Forms.WebBrowser?

.netbrowser

提问by Bill Daugherty

How can you scroll to the end of a System.Windows.Forms.WebBrowser programmatically?

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

回答by Tarsier

ctlWebBrowser.Document.Body.ScrollIntoView(false);

The boolean parameter for ScrollIntoView() is true to align the scrollbar with the top of the document, and false to align the scrollbar with the bottom of the document.

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

MSDN documentation here: HtmlElement.ScrollIntoView

此处的 MSDN 文档:HtmlElement.ScrollIntoView

回答by yclkvnc

I'm setting DocumentTextproperty of the WebBrowsercontrol (with html and body tags) and Document.Body.ScrollIntoView(false)method didn't worked for me, but this is working:

我正在设置控件的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);
        }
    }

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

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

回答by hey

When I had no ending bodyelement, this worked for me (VB.NET):

当我没有结束body元素时,这对我有用(VB.NET):

WebBrowser1.Document.Body.All(WebBrowser1.Document.Body.All.Count - 1).ScrollIntoView(False)

回答by anonymous

wb1.Navigate("javascript:window.scroll(0,document.body.scrollHeight);")

回答by serial8

Adding to user2349661's answer this is the same for C#:

添加到 user2349661 的答案中,这与 C# 相同:

WebBrowser1.Document.Body.All[WebBrowser1.Document.Body.All.Count -1].ScrollIntoView(False)

n.b. would have added as a comment but I don't have enough points!

nb 会添加为评论,但我没有足够的积分!

回答by Patrice I

Using javascript creates ie security problems

使用 javascript 会产生 ie 安全问题

webBrowser.Navigate("javascript:window.scroll(...);")

It is better to use a direct call like

最好使用像这样的直接调用

webBrowser.Document.Window.ScrollTo(...)

回答by Rusty Nail

Inside a Document Completed event would be a good option:

在 Document Completed 事件中将是一个不错的选择:

private void Form1_Load(object sender, EventArgs e)
{

webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted;
webBrowser1.Navigate("http://stackoverflow.com/questions/990651/how-to-scroll-to-end-of-system-windows-forms-webbrowser");

}


private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{

WebBrowser browser = sender as WebBrowser;

browser.Document.Body.ScrollIntoView(false);

}