Delphi ScrollBox1滚动框鼠标滚轮


本文整理自网络,侵删。

 
//方法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;

相关阅读 >>

Delphi 防止刷新时闪烁的终极解决办法

Delphi xe webbroker 开发,解决 response 返回中文乱码问题

Delphi 操作 pdf -- 使用 acrobat sdk 初探

Delphi 如何从html格式的字符串中提取纯文本?

Delphi comparedatetime、comparedate、comparetime、samedatetime、samedate、sametime �c 对比时间的函数

Delphi 读取流信息

Delphi 使用泛型的 tarray 从动态数组中查找指定元素

Delphi web service 多表提交的事务管理

Delphi 10.3.1 android沉浸式透明状态栏

Delphi 如何确定屏幕分辨率

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...