Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

browser

.net

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

like image 796
William Daugherty Avatar asked Jun 13 '09 13:06

William Daugherty


3 Answers

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.

MSDN documentation here: HtmlElement.ScrollIntoView

like image 126
Tarsier Avatar answered Nov 15 '22 16:11

Tarsier


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

    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/

like image 13
yclkvnc Avatar answered Nov 15 '22 17:11

yclkvnc


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

WebBrowser1.Document.Body.All(WebBrowser1.Document.Body.All.Count - 1).ScrollIntoView(False)
like image 1
hey Avatar answered Nov 15 '22 16:11

hey