学习学习:鼠标移入称出控件的消息:DELPHI预定义的两个消息: CM_MOUSEENTER 和 CM_MOUSELEAVE。 Below 已经提供了部分使用它们的代码, 我试了,对TSPEEDBUTTON有效,相信对其它也有效。 unit SomeForm; interface type TSomeForm = class(TForm) private procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER; procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE; end; implementation procedure TSomeForm.CMMouseEnter(var Msg: TMessage); var anObject : TObject; begin { anObject is the control over which the mouse is right now } anObject := TObject(Msg.lParam); if anObject nil then begin { First, you must find WHICH is the control under the mouse cursor, } { then, determine what action to do, etc... } end; end; procedure TSomeForm.CMMouseLeave(var Msg: TMessage); begin { anObject is the control which the mouse has just gone out of } anObject := TObject(Msg.lParam); if anObject nil then begin { First, you must find WHICH is the control } { the mouse cursor has just left, } { then, determine what action to do, etc... } end; end; end.
CM_MOUSEENTER 和 CM_MOUSELEAVE。 Below 已经提供了部分使用它们的代码,
我试了,对TSPEEDBUTTON有效,相信对其它也有效。
unit SomeForm;
interface
type
TSomeForm = class(TForm)
private
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
end;
implementation
procedure TSomeForm.CMMouseEnter(var Msg: TMessage);
var
anObject : TObject;
begin
{ anObject is the control over which the mouse is right now } anObject := TObject(Msg.lParam);
if anObject nil then begin
{ First, you must find WHICH is the control under the mouse cursor, }
{ then, determine what action to do, etc... }
end;
end;
procedure TSomeForm.CMMouseLeave(var Msg: TMessage);
begin
{ anObject is the control which the mouse has just gone out of }
anObject := TObject(Msg.lParam);
if anObject nil then begin
{ First, you must find WHICH is the control }
{ the mouse cursor has just left, }
{ then, determine what action to do, etc... }
end;
end;
end.
Y: Integer);
begin
panel1.Caption:='鼠标在我上面';
end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
panel1.Caption:='鼠标不在我上面';
end;