Skip to main content

TcxScrollBar.OnScroll Event

Enables you to respond to thumb scrolling.

Declaration

property OnScroll: TScrollEvent read; write;

Remarks

Handle this event to respond to end-user thumb scrolling and adjust the resulting scrollbar value accordingly.

The Sender parameter provides access to the scrollbar that fired the event.

The ScrollCode parameter identifies the end-user action that initiated thumb scrolling. Once thumb scrolling is finished, this parameter returns scEndScroll.

The ScrollPos parameter contains a new Position property value to be assigned as the result of thumb scrolling. You can adjust this value as required.

The following code example demonstrates how to handle the OnScroll event to cancel any end-user thumb scrolling based on a specific condition.

var
  AStoredPos: Integer = -1;
// ...
procedure <Form>.<cxScrollBar>Scroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
begin
  if (ScrollCode <> scEndScroll) and (AStoredPos = -1) then
    AStoredPos := cxScrollBar1.Position
  else if (<Your condition here>) and (ScrollCode = scEndScroll) then
  begin
    ScrollPos := AStoredPos;
    AStoredPos := -1;
  end;
end;
See Also