Results 1 to 5 of 5

Thread: Detect if panel scrollbar being used

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Detect if panel scrollbar being used

    Hi

    I've got a panel with a label control inside. It's set to autoscroll.

    I'm updating the label every 5 seconds (on a timer) with the last 20 lines of a text file via a background worker.

    The background worker sets the vertical scrollbar on the panel to maximum each time, so that it scrolls to the bottom and the user sees the most recent text file entries.

    So far so good - what I'd now like to do is to skip the label update if the user is dragging the scrollbar when the timer fires.


    To do this, I thought I could set a flag using MouseEnter and MouseLeave events - so if the mouse is within the control, it flags as true and the timer doesn't start the background worker. When the mosue leaves, the flag is false, and the timer fires on the next tick.

    This fails because the MouseEnter does not fire when the mouse is over the scrollbar itself.

    I can use the Scroll event, but there's no 'Scroll off' event to signify the user has stopped scrolling.

    This is one of those things which you feel should be simple, but it has got me stumped at the moment! - could anyone suggest a solution please?

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Detect if panel scrollbar being used

    If there are no events then there are no events. What you might do is create a derived class and override the WndProc method. You can then see what messages the control receives from Windows and you may find that there are specific messages that correspond to the start and end of a scroll operation. You could then declare appropriate events in your derived class and raise them when those messages are received. If there are no such messages then you may be out of luck, short of actually accessing the scrollbar window within the Panel.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Re: Detect if panel scrollbar being used

    Quote Originally Posted by jmcilhinney View Post
    If there are no events then there are no events. What you might do is create a derived class and override the WndProc method. You can then see what messages the control receives from Windows and you may find that there are specific messages that correspond to the start and end of a scroll operation. You could then declare appropriate events in your derived class and raise them when those messages are received. If there are no such messages then you may be out of luck, short of actually accessing the scrollbar window within the Panel.
    Thanks - sounds complicated for what I need, but it is what it is I guess. I'll look into it.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Detect if panel scrollbar being used

    I would suggest a couple different things.

    1) Do you get scroll events? If so, then the scroll changed tells you that the mouse is 'doing something to the scroll bar'. That may not be enough, but it's something.
    2) If you were to track all mouse movements, you could get the mouse position in either form coordinates, panel coordinates, or screen coordinates. From that, you can figure out for yourself where the mouse is, and whether it is over any part of the form (panel, scrollbar, or whatnot). All you'd need is to get all mouse move events (or even all mouse events) for the form or application.

    The drawback to this is that you will be deluged with them, so you need to be right quick to decide to do something or not. If all you are doing is checking whether the mouse coordinates fell into a rectangle, that would be super fast, and it sounds like you are effectively just setting a Boolean when in or when out, and only taking action when the Boolean changes state.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Re: Detect if panel scrollbar being used

    Quote Originally Posted by Shaggy Hiker View Post
    I would suggest a couple different things.

    1) Do you get scroll events? If so, then the scroll changed tells you that the mouse is 'doing something to the scroll bar'. That may not be enough, but it's something.
    2) If you were to track all mouse movements, you could get the mouse position in either form coordinates, panel coordinates, or screen coordinates. From that, you can figure out for yourself where the mouse is, and whether it is over any part of the form (panel, scrollbar, or whatnot). All you'd need is to get all mouse move events (or even all mouse events) for the form or application.

    The drawback to this is that you will be deluged with them, so you need to be right quick to decide to do something or not. If all you are doing is checking whether the mouse coordinates fell into a rectangle, that would be super fast, and it sounds like you are effectively just setting a Boolean when in or when out, and only taking action when the Boolean changes state.
    Hi

    Thanks for your post - I'll look into this too. I don't want to spend too much time on it as it's a bit of a distraction from the rest of the program I should be working on!

    You've both given me somewhere to start though, which is much appreciated.

Tags for this Thread

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