Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I scroll the WebBrowser control

80 views
Skip to first unread message

Futronics Developer

unread,
May 13, 2008, 8:00:01 AM5/13/08
to
I'm trying to do my own scrolling with the WebBrowser control (2 large
buttons next to the control).

I can use the WebBrowser.Document.Window.ScrollTo method to scroll to a
specific position but how do I find my current position?

I can keep my own scroll position, I know when the document loads that I'm
at scroll position 0,0. Then each time I scroll (by 200 for example) I just
keep a record of my new scroll position.

This works until I get to the end of the document. The ScrollTo doesn't
return any feedback when it gets to the end of the document, like 'stop' or
'can't scroll' or 'have only scrolled 50'. When the end of the docuument is
reached I would still be calling ScrollTo adding 200 each time to my internal
scroll position. The two would get out-of-sync.

Is there a way to read the current scroll position?


Tor Vidvei

unread,
Dec 5, 2010, 3:39:03 AM12/5/10
to
You can read the scroll position from the Body element of the document by using the properties ScrollTop, ScrollLeft or ScrollRectangle. Do something like this:

Rectangle scrollRect // X,Y: Scroll position; Width,Height: Size of document

HtmlElement body = webBrowser1.Document.GetElementsByTagName("body")[0];
if (body != null) scrollRect = body.ScrollRectangle;


Tor


> Submitted via EggHeadCafe
> Microsoft ASP.NET For Beginners
> http://www.eggheadcafe.com/training-topic-area/ASP-NET/7/ASP.aspx

0 new messages