获得MouseDown消息(100分)

  • 主题发起人 主题发起人 fhb
  • 开始时间 开始时间
F

fhb

Unregistered / Unconfirmed
GUEST, unregistred user!
我创建了控件A,放在Form1上,Panel1也放在Form1上,
如何获得Panel1或Form1的MouseDown消息呢?
 
parent even?
 
补充:控件A如何获得Panel1或Form1的MouseDown消息呢?
 
在Panel1或Form1的OnMouseDown事件中告诉控件A就可以了...
 
autumn:相关控件
Mycomponent = class(TCustomControl)
public
relateComponent:TComponent
..

end;

我想控件A直接知道relateComponent的Mouse有关消息,
而不用在Panel1或Form1的OnMouseDown事件中去告诉控件A。

 
自己写控件啊,
没办法了,这样:
定义:
OldOnmouseDown: ???(不记得是什么了),
mymouseDown: ???

在mymouseDown中
触发relatemouseDown事件
然后OldOnmouseDown;

在setRelateComponent过程中
OldOnmouseDown := RelateComponent.OnMouseDown
RelateComponent.OnMouseDown := mymouseDown;
释放或更换时恢复;
大致如此,机器不在身边,什么都记不起来...:(

 
DoubleWood:能不能写详细一点?或有源码吗?
非常感谢!
 
type
TMyMouseEvent = procedure(Sender:TObject; Realte:TControl; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer; Var DoIt: Boolean);

TMycomponent = class(TCustomControl)
private
...
fRelateComponent: TControl;
fOldOnMouseDown: TMouseEvent;
fRelateComponentMouseDown: TMyMouseEvent;
procedure NewOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SetRelateComponent(Value: TControl);
public
...
published
...
property RelateComponent: TControl read fRelateComponent write SetRelateComponent;
property OnRelateComponentMouseDown: TMyMouseEvent read fRelateComponentMouseDown write fRelateComponentMouseDown;
end;

procedure TMycomponent.SetRelateComponent(Value: TControl);
begin
if Assigned(fRelateComponent) then
fRelateComponent.OnMouseDown := fOldOnMouseDown;
fRelateComponent := Value;
if Assigned(fRelateComponent) then
begin
fOldOnMouseDown := fRelateComponent.OnMouseDown;
fRelateComponent.OnMouseDown := NewOnMouseDown;
end
else
fOldOnMouseDown := nil;
end;
procedure TMycomponent.NewOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
DoIt: Boolean;
begin
if assigned(fRelateComponentMouseDown) then
fRelateComponentMouseDown(Sender, fRelateComponent, Button, Shift, X, Y, DoIt);
if Doit then
fOldOnMouseDown(Sender, Button, Shift, X, Y);
end;
大致如此,没有经过测试。
 
接受答案了.
 
后退
顶部