Recent

Author Topic: Onscroll event for TscrollBox (in +, for Tform)  (Read 135 times)

laz_one_or2

  • Newbie
  • Posts: 2
Onscroll event for TscrollBox (in +, for Tform)
« on: June 16, 2026, 11:16:39 am »
hip !
i mod TscrollBox ancestor(TScrollingWinControl), because many less code than if i mod only Tscrollbox.
Tform is a descendant of TScrollingWinControl, it gain the event, the more useful thing i never see :).
this works for me on windows 11, fedora 44, hope for you too.

i got help from these posts :
https://forum.lazarus.freepascal.org/index.php?topic=28556.0
https://forum.lazarus.freepascal.org/index.php?topic=31550.0

In forms.pp :
Code: Pascal  [Select][+][-]
  1.   { TScrollingWinControl }
  2.  
  3.     TScrollEvent = procedure(Sender: TObject; var ScrollPos: Integer) of object;  {onscroll}
  4.  
  5.  
  6.   TScrollingWinControl = class(TCustomControl)
  7.  
  8.   strict private                {onscroll}
  9.     FOnVScroll: TScrollEvent;   {onscroll}
  10.     FOnHScroll: TScrollEvent;   {onscroll}
  11.  
  12.           published
  13.  
  14.         property OnVScroll: TScrollEvent read FOnVScroll write FOnVScroll; {onscroll}
  15.         property OnHScroll: TScrollEvent read FOnHScroll write FOnHScroll; {onscroll}

in scrollingwincontrol.inc :

Code: Pascal  [Select][+][-]
  1.        
  2. procedure TScrollingWinControl.WMVScroll(var Message : TLMVScroll);
  3.         begin
  4.           VertScrollbar.ScrollHandler(Message);
  5.            if Assigned(FOnVScroll) then
  6.                   FOnVScroll(Self, FVertScrollBar.FPosition);{onscroll}
  7.         end;
  8.  
  9.         procedure TScrollingWinControl.WMHScroll(var Message : TLMHScroll);
  10.         begin
  11.           //DebugLn(['TScrollingWinControl.WMHScroll ',dbgsName(Self)]);
  12.           HorzScrollbar.ScrollHandler(Message);
  13.           if Assigned(FOnHScroll) then
  14.              FOnHScroll(Self, FHorzScrollBar.FPosition);{onscroll}
  15.         end;      
« Last Edit: June 16, 2026, 11:19:52 am by laz_one_or2 »

 

TinyPortal © 2005-2018