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?
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:TimerStart()s, using anIntervalof ~200ms when the button goes down. The mouse is alsoCaptured at this point.Tickeffects a scroll. (The firstTickalso changes the interval to ~25ms)Timer.Stop()s.The changing of the
Intervalfrom200to25means 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).