Delphi 7 - 在窗体中处理嵌入式框架的MouseWheel事件? [英] Delphi 7 - Handling MouseWheel events for Embedded Frames in Forms?
问题描述
对于某些框架,我希望滚动内容(或至少处理鼠标事件)。
我尝试过以下操作:
只需为每个框架分配OnMouseWheel事件处理程序
覆盖父窗体的MouseWheel事件:
过程TFmReview.MouseWheelHandler(var Message :TMessage);
var Control:TControl;
begin
控制:= ControlAtPos(ScreenToClient(SmallPointToPoint(TWMMouseWheel(Message).Pos)),False,True);
如果Assigned(Control)和(Control<> ActiveControl)然后
begin
ShowMessage(Control.Name);
Message.Result:= Control.Perform(CM_MOUSEWHEEL,Message.WParam,Message.LParam);
如果Message.Result = 0,那么
Control.DefaultHandler(Message);
end else继承MouseWheelHandler(Message);
结束
不幸的是,似乎没有工作。
- 在情况1中,事件永远不会被触发,但父表单鼠标滚轮处理程序被触发。
- 在情况2中,接收焦点的控件是保存要发送滚轮事件的帧的面板。因此,简单来说,我如何将鼠标滚轮事件指向鼠标光标结束的最顶级控件(无论哪一方面)框架/父/表格等)?解决方案
将鼠标滚轮处理推迟到
TWinControl
目前是鼠标光标,在您的主框架中覆盖MouseWheelHandler
方法使用如下代码:键入
TMainForm = class(TForm)
private
procedure MouseWheelHandler(var AMessage:TMessage);覆盖
public
{公开声明}
end;
实现
程序TMainForm.MouseWheelHandler(var AMessage:TMessage);
var
控制:TWinControl;
begin
控制:= FindVCLWindow(SmallPointToPoint(TWMMouseWheel(AMessage).Pos));
如果分配(控制)然后
begin
AMessage.Result:= Control.Perform(CM_MOUSEWHEEL,AMessage.WParam,
AMessage.LParam);
如果AMessage.Result = 0然后
Control.DefaultHandler(AMessage);
end
else
继承了MouseWheelHandler(AMessage);
结束
Hi I have a form with several frames inside.
For some of the frames, i wish to scroll the contents (or at least handle the mousewheel event).
I have tried the following:
Simply assigning a OnMouseWheel event handler for each frame
Overriding the MouseWheel event for the parent form:
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;
Unfortunately both dont seem to work.
- In case 1, the event is never triggered, however the parent forms mouse wheel handler is triggered.
- In case 2, the control that receives focus is the panel that holds the frame i wish to send the mousewheel event to.
So, put simply, how can i direct the mousewheel event to the top most control that the mouse cursor is over (regardless of which frame/parent/form etc the cursor is in)?
解决方案To postpone mouse wheel handling to a
TWinControl
over which is currently mouse cursor, override in your main frame form theMouseWheelHandler
method using a code like this: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;
这篇关于Delphi 7 - 在窗体中处理嵌入式框架的MouseWheel事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!