Search code examples
delphiscrollbaronchangemousepress

How to Detect that the Mouse is unmoved and button still pressed?


In Delphi, I've added a Scrollbar component (oriented vertical) to the right side of my form.

I've added a Scrollbar OnChange event so I can change the view of the form and the position of the scrollbar thumb when the user clicks on the UpArrow or DownArrow button with his mouse, and this works fine.

But the OnChange event only seems to get triggered when the mouse button is initially pressed on the arrow.

I notice all scrollbar controls repeat the command and continue scrolling while the mouse remains pressed on the arrow, and I'd like to implement this behavior.

So how can I easily detect if the user has not moved the mouse and continues to press the mouse button while the mouse remains over the arrow?


Conclusion. Somehow something in the scrollbar in my project got corrupted. After I deleted the ScrollBar, and added it again, the problem vanished.

This is one of those tricky ones that took me a lot of time to solve. Thanks for your help. I'm closing this question.


Solution

  • Use the OnScroll event.

    The following code adds 'xxx' to a memo as long as the mouse is held down on the scrollbar arrow button. Tested with Delphi 6.

    procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    begin
        Memo1.Lines.Add( 'xxx' );
    end;