Skip to content
July 19, 2010 / kiranpatils

WebBrowserControl Scroll to Bottom

Challenge

I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display the messages between the user and the recipient. How do I get the control to automatically scroll to the bottom every time I update the DocumentText of the control?

Solution

I tried to Google it and found below stuff which doesn’t work as expected.

ctlWebBrowser.Document.Body.ScrollIntoView(false);

// http://stackoverflow.com/questions/990651/system-windows-forms-webbrowser-scroll-to-end

webCtrl.Document.Window.ScrollTo(0, int.MaxValue);

// http://stackoverflow.com/questions/46454/webbrowsercontrol-scroll-to-bottom
Finally, I did it using following way:

private void ScrollMessageIntoView()
 {
 // MOST IMP : processes all windows messages queue
 System.Windows.Forms.Application.DoEvents();

 if (webBrowserControlRcdMsg.Document != null)
 {

webBrowserControlRcdMsg.Document.Window.ScrollTo(0,
webBrowserControlRcdMsg.Document.Body.ScrollRectangle.Height);

 }
 }

Thanks to this Link : http://social.msdn.microsoft.com/forums/en-US/winforms/thread/74694382-dc0d-4824-ac8f-3a4046f45111/

One Comment

Leave a Comment
  1. Huguet / Nov 29 2013 3:26 pm

    It works fine. Merci !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: