How can you scroll to the end of a System.Windows.Forms.WebBrowser programmatically?
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
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/
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With