views:

488

answers:

1

I want to implement a custom scrollbar but want it to work like the standard one. So I need to detect that the mouse button is held down over either the up or down arrow at the ends of the bar so that the user can scroll using the bar ends.

How can I detect that the button is being held?

MouseDown only fires once when the button is first pressed. MouseUp will fire when the button is released but is there a better way than to have some sort of timer that triggers periodically between MouseDown and MouseUp?

+1  A: 

I don't think you're going to be able to do better than using a Timer (although I may be surprised).

I've used Timers before for the same purpose, and they work, usually like this:

  • The Timer Start()s, using an Interval of ~200ms when the button goes down. The mouse is also Captured at this point.
  • Each Tick effects a scroll. (The first Tick also changes the interval to ~25ms)
  • When the mouse comes up, the Timer.Stop()s.

The changing of the Interval from 200 to 25 means that they have to hold the mouse down for a while, but once they do, the scrolling action happens more quickly/smoothly.

The button being "held" really isn't an event, it's more of a state (i.e. it doesn't occur at a specific point in time).

Daniel LeCheminant