说起来很麻烦的,我先把代码贴出来,你先看看
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Button1: TButton;
Button2: TButton;
Panel4: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
pa:TPOINT;
i:Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(application.Handle,gwl_exstyle,ws_ex_toolwindow);
timer1.Interval:=1;
timer1.Enabled:=true;
timer2.Enabled:=false;
Button2.Top:=200;
panel4.Top:=Button2.Top+25;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
GetCursorPos(pa);
if Form1.top<30 then
begin
Form1.Top:=0;
if (pa.x<Form1.Left) or (pa.x>(Form1.left+Form1.width)) or (pa.y>Form1.Height) then
Form1.Visible:=False
else
Form1.visible:=True;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button2.Top<100 then begin
Timer2.Interval:=1;
Timer2.Enabled:=true;
i:=0;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if Button2.Top>100 then begin
Timer2.Interval:=1;
Timer2.Enabled:=true;
i:=1;
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
if i=0 then begin if Button2.Top<200 then
Button2.Top:=Button2.Top+4; end;
if i=1 then begin if Button2.Top>24 then
Button2.Top:=Button2.Top-4; end;
panel4.Top:=Button2.Top+25;
if Button2.Top=200 then timer2.Enabled:=false;
if Button2.Top=24 then timer2.Enabled:=false;
end;
end.
在form上的放置层次如下:
panel1
button1
speedbutton1
speedbutton2
panel2
button2
speedbutton3
speedbutton4
原理:当单击button1时,用timer控制panel2缓慢下移,panel1显示出来。
但单击button2时,用timer控制panel1缓慢下移,panel2显示出来。
刚把演示程序传上去,下下来自己看看吧!很简单的。
http://iapollo.diy.163.com/mywork/delphi/fQQ.rar