嗨我有一个内有几个框架的表格。
对于某些帧,我希望滚动内容(或者至少处理鼠标滚轮事件)。
我尝试了以下内容:
只需为每个帧分配一个OnMouseWheel事件处理程序
覆盖父窗体的MouseWheel事件:
procedure TFmReview.MouseWheelHandler(var Message: TMessage);
var Control: TControl;
begin
Control := ControlAtPos(ScreenToClient(SmallPointToPoint(TWMMouseWheel(Message).Pos)), False, True);
if Assigned(Control) and (Control <> ActiveControl) then
begin
ShowMessage(Control.Name);
Message.Result := Control.Perform(CM_MOUSEWHEEL, Message.WParam, Message.LParam);
if Message.Result = 0 then
Control.DefaultHandler(Message);
end else inherited MouseWheelHandler(Message);
end;
不幸的是,两者似乎都没有用。
因此,简单地说,如何将鼠标滚轮事件指向鼠标光标所在的最顶层控件(无论光标位于哪个帧/父/窗体等)?
答案 0 :(得分:1)
要将鼠标滚轮处理推迟到当前鼠标光标所在的TWinControl
,请使用如下代码在主框架中覆盖MouseWheelHandler
方法:
type
TMainForm = class(TForm)
private
procedure MouseWheelHandler(var AMessage: TMessage); override;
public
{ Public declarations }
end;
implementation
procedure TMainForm.MouseWheelHandler(var AMessage: TMessage);
var
Control: TWinControl;
begin
Control := FindVCLWindow(SmallPointToPoint(TWMMouseWheel(AMessage).Pos));
if Assigned(Control) then
begin
AMessage.Result := Control.Perform(CM_MOUSEWHEEL, AMessage.WParam,
AMessage.LParam);
if AMessage.Result = 0 then
Control.DefaultHandler(AMessage);
end
else
inherited MouseWheelHandler(AMessage);
end;