鸿 网 互 联 www.68idc.cn

Delphi ScrollBox1滚动框鼠标滚轮

来源:互联网 作者:佚名 时间:2021-12-14 17:55
//方法1:procedure TForm1.ScrollBoxMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);var LTopLeft, LTopRight, LBottomLeft, LBottomRight: SmallInt; LPoint: TPoint; ScrollBox: TScrol
//方法1:procedure TForm1.ScrollBoxMouseWheel(Sender: TObject;  Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;  var Handled: Boolean);var  LTopLeft, LTopRight, LBottomLeft, LBottomRight: SmallInt;  LPoint: TPoint;  ScrollBox: TScrollBox;begin  ScrollBox := TScrollBox(Sender);  LPoint := ScrollBox.ClientToScreen(Point(0,0));  LTopLeft := LPoint.X;  LTopRight := LTopLeft + ScrollBox.ClientWidth;  LBottomLeft := LPoint.Y;  LBottomRight := LBottomLeft + ScrollBox.ClientWidth;  if (MousePos.X >= LTopLeft) and    (MousePos.X <= LTopRight) and    (MousePos.Y >= LBottomLeft) and    (MousePos.Y <= LBottomRight) then  begin    ScrollBox.VertScrollBar.Position := ScrollBox.VertScrollBar.Position - WheelDelta;    Handled := True;  end;end;//方法2:procedure TForm1.ScrollBox1MouseWheel(Sender: TObject; Shift: TShiftState;  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);begin  Handled := True;  if WheelDelta < 0 then    TScrollBox(Sender).VertScrollBar.Position := TScrollBox(Sender).VertScrollBar.Position + TScrollBox(Sender).VertScrollBar.Increment  else    TScrollBox(Sender).VertScrollBar.Position := TScrollBox(Sender).VertScrollBar.Position - TScrollBox(Sender).VertScrollBar.Increment;end;
网友评论
<