Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I scroll a TScrollbar using the mouse wheel?

I have a TScrollBar having a code in the OnScroll event.

I want to scroll it using the mouse wheel, but turning the mouse wheel does not scroll the scroll bar and does not trigger the OnScroll event.

Any idea?

like image 594
XBasic3000 Avatar asked Aug 15 '11 09:08

XBasic3000


2 Answers

procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
  I: Integer;
begin
  Handled := PtInRect(ScrollBox1.ClientRect, ScrollBox1.ScreenToClient(MousePos));
  if Handled then
    for I := 1 to Mouse.WheelScrollLines do
    try
      if WheelDelta > 0 then
        ScrollBox1.Perform(WM_VSCROLL, SB_LINEUP, 0)
      else
        ScrollBox1.Perform(WM_VSCROLL, SB_LINEDOWN, 0);
    finally
      ScrollBox1.Perform(WM_VSCROLL, SB_ENDSCROLL, 0);
    end;
end;
like image 100
Stefan Avatar answered Nov 08 '22 14:11

Stefan


it's too easy just increase the position Value .

procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
self.VertScrollBar.Position :=  self.VertScrollBar.Position + WheelDelta;
end;
like image 38
Safwat Safwat Avatar answered Nov 08 '22 14:11

Safwat Safwat