Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know when I've stopped scrolling a TScrollBar?

I've used some programs with scroll bars that update the linked content while you're still dragging the "thumb", and others that don't until you release the mouse. This implies that there are different types of Windows messages involved here. But all I can find from TScrollBar is an OnScroll event which fires continually while you're dragging. It also doesn't have a OnMouseDown or OnMouseUp event. Is there any way to set up an "OnEndDragging" notification for a TScrollBar?

like image 208
Mason Wheeler Avatar asked Dec 02 '25 19:12

Mason Wheeler


1 Answers

Try this code (tested with Delphi 2009), it will fill the form client area with a random colour while you track the thumb, and fill it in yellow when the thumb is released:

procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
  Randomize;
  if ScrollCode = scTrack then
    Color := RGB(Random(256), Random(256), Random(256));
  if ScrollCode = scEndScroll then
    Color := clYellow;
end;

The TScrollCode values map to the WPARAM values that you will find documented for WM_HSCROLL and WM_VSCROLL.

like image 157
mghie Avatar answered Dec 04 '25 23:12

mghie