处理控件消息CM_MOUSEENTER和CM_MOUSELEAVE即可。
举一个例子如下:
创建一个类
unit ShrinkPanel;
interface
uses
Messages, Controls, ExtCtrls;
type
TShrinkPanel=class (TPanel)
private
procedure CMMouseLeave(var Msg:TMessage); message CM_MOUSELEAVE;
end;
implementation
procedure TShrinkPanel.CMMouseLeave(var Msg:TMessage);
begin
Visible:=False;
end;
end.
写代码如下:
...
Panel:TShrinkPanel;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
Panel:=TShrinkPanel.Create(Self);
with Panel do begin
Parent:=Self;
Align:=alTop;
Height:=20;
Visible:=False;
end;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Y<Panel.Height then Panel.Visible:=True;
end;