views:

697

answers:

3

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?

+1  A: 

I would use the AutoScrollOffset property and set it the the bottom left of the WebBrowser control, so something like:

webCtrl.AutoScrollOffset = new Point(webCtrl.Height, 0);
Oded
+1  A: 

This is probably overkill, but you could also invoke script on the WebBrowser control and then use the scroll properties of the body tag. Or the scrollTo method of the window.

To invoke script, the WebBrowser control has a Document property that represents the document object from the DOM. It has a method called InvokeScript that you can pass a string of JavaScript to be executed.

But... if the AutoScrollOffset property works... yeah, I'd just use that instead of getting into JavaScript :)

David Mohundro
A: 

Thanks guys -- I voted you both up but neither would work out for my situation. What I ended up doing was

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