How to vertical scroll down in web browser control

2020-02-11 09:13发布

How can I scroll down the scroll bar in WebBrowser component in c#?
I tried the following code , but it doesn't did the job:

webBrowser2.Focus();
webBrowser2.Document.Body.ScrollIntoView(false);

1条回答
地球回转人心会变
2楼-- · 2020-02-11 09:34

To scroll to a specific location, you can use WebBrowser.Document.Window.ScrollTo(x,y) method. For example to scroll down to the end of body:

private void webBrowser1_DocumentCompleted(object sender, 
                                           WebBrowserDocumentCompletedEventArgs e)
{
    webBrowser1.Document.Window.ScrollTo(0, webBrowser1.Document.Window.Size.Height);
}

To scroll to a specific element, you can use ScrollIntoView method.

查看更多
登录 后发表回答