Results 1 to 6 of 6

Thread: WebBowser scrolling

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    WebBowser scrolling

    Can i use buttons to scroll up and down a web page instead of using the scroll bars from the web browser control. If so, how? Does anyone know the codes to do it?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: WebBowser scrolling

    Sure, the issue is that this method doesn't work %100 of the time. First you turn Option Strict and Explicit On:
    Code:
    Option Strict On
    Option Explicit On
    Public Class Form1
    
    End Class
    Then add your two buttons to the form.

    Then generate the click events for each button:
    Code:
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            'Up
    
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            'Down
    
        End Sub
    For the scroll up and down, you set the webbrowser's document's body's scrolltop property. To scroll left to right, you set the Body's scroll left property. Here is the code for the up and down scrolling:
    Code:
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            'Up
            WebBrowser1.Document.Body.ScrollTop -= 1
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            'Down
            WebBrowser1.Document.Body.ScrollTop += 1
        End Sub
    But like I said, that won't work %100 of the time. A sure fire method that should work is the WebBrowser.Document.Window.ScrollTo method. The issue with this is that you scroll to a specific point, instead of scrolling up or down by x amount.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: WebBowser scrolling

    Quote Originally Posted by dday9 View Post
    Sure, the issue is that this method doesn't work %100 of the time. First you turn Option Strict and Explicit On:

    But like I said, that won't work %100 of the time. A sure fire method that should work is the WebBrowser.Document.Window.ScrollTo method. The issue with this is that you scroll to a specific point, instead of scrolling up or down by x amount.
    Thanks Dday, is there a way to scroll only 3 or four lines at a time using your last method?

  4. #4
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Re: WebBowser scrolling

    This brings up a great feature that should be added to firefox/chrome etc. You know how when you refresh a page...while reading an article... it will take you back to your last position?
    That seems as if there is something in the code specifying your 'location' on the page. So why not have a feature that allows you to automatically skip to your favorite position...say the celebrity/entertainment area on news.google.com.. everytime you load it
    I suppose there could also be a plugin...where you could hit buttons for certain websites... for like Google News that say like [tech] [top stories] [sports] etc. Instead of wasting 5 seconds scrolling to the correct position or having to click a link that will load ONLY those stories etc.

    Sorry thought it was a good idea....didn't mean to rain on your post with non-relevant information <3
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    19

    Re: WebBowser scrolling

    I think she^ has a good idea. Would it be possible to get the location of were you were last at on the webpage when you refreshed. Say you were on a web page that had 1000's of words on it and you highlighted one word and clicked a button and then left the page then when you came back to that page and clicked a button it would re-highlight that word and scroll the web browser to that word. Would that be the slightest bit possible?

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: WebBowser scrolling

    @Richard, start you own thread. This prevents cluttering of existing threads.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width