delphi - 滚动框鼠标滚轮delphi
问题描述
如何OnMouseWheel
为两个滚动框添加到同一个表单中?我应用了该方法,ScrollBox1
但我不知道如何将该方法添加到ScrollBox2
procedure TForm3.FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
LTopLeft, LTopRight, LBottomLeft, LBottomRight: SmallInt;
LPoint: TPoint;
begin
inherited;
LPoint := ScrollBox1.ClientToScreen(Point(0,0));
LTopLeft := LPoint.X;
LTopRight := LTopLeft + ScrollBox1.Width;
LBottomLeft := LPoint.Y;
LBottomRight := LBottomLeft + ScrollBox1.Width;
if (MousePos.X >= LTopLeft) and
(MousePos.X <= LTopRight) and
(MousePos.Y >= LBottomLeft)and
(MousePos.Y <= LBottomRight) then
begin
ScrollBox1.VertScrollBar.Position :=
ScrollBox1.VertScrollBar.Position - WheelDelta;
Handled := True;
end;
end;
解决方案
将相同的处理程序分配给两个 ScrollBox 组件,而不是分配给 Form,然后使用Sender
参数知道哪个组件正在调用处理程序。
procedure TForm3.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;
推荐阅读
- maven - 如何配置一组默认属性以在每个新的 Maven 项目中使用?
- svelte - 如何在 SvelteKit 中从 css-in-js 构建静态 css 样式表?
- selenium - 有什么方法可以轻松地将 ChromeDriver 添加到程序中
- firebase - 为什么我的 Firebase 动态链接会变成分支动态链接?
- typescript - Firebase 函数在尝试部署时导致错误
- linux - $${!} 在 bash 中是什么意思?
- unity3d - 使用 Sprite Shape Controller 编辑创建一个圆
- laravel - 在 Laravel Nova 中上传多张图片
- javascript - Javascript If 语句 HTML
- javascript - 如何获取并等待 5 秒并获取页面的源代码