我也说两句,大虾们莫笑!
不用第三方的控件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,ExtCtrls, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Button1: TButton; {控制动画的播放和停止}
ScrollBar1: TScrollBar;
SpeedLable: TLabel; {控制播放的速度}
Fast: TLabel;
Slow: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ScrollBar1Change(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
Bmp1,Bmp2:TBitmap;
FS,Key:Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Bmp1:=TBitmap.Create;
Bmp2:=TBitmap.Create;
Bmp1.LoadFromFile('drawing1.bmp');
Bmp2.LoadFromFile('drawing2.bmp');
Key:=False;
if Key=True then
begin
Timer1.Enabled:=True;
Form1.Button1.Caption:='ON';
end
else
begin
Timer1.Enabled:=False;
ScrollBar1.Visible:=False;
Fast.Visible:=False;
SpeedLable.Visible:=False;
Slow.Visible:=False;
Form1.Button1.Caption:='OFF';
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if FS=True then Image1.Picture.Graphic:=Bmp1
else Image1.Picture.Graphic:=Bmp2;
FS:=Not FS;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Key:=Not Key;
if Key=True then
begin
Timer1.Enabled:=True;
ScrollBar1.Visible:=True;
Fast.Visible:=True;
SpeedLable.Visible:=True;
Slow.Visible:=True;
Form1.Button1.Caption:='ON';
end
else
begin
Timer1.Enabled:=False;
ScrollBar1.Visible:=False;
Fast.Visible:=False;
SpeedLable.Visible:=False;
Slow.Visible:=False;
Form1.Button1.Caption:='OFF';
end;
end;
procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
Timer1.Interval:=ScrollBar1.position*5+1;
SpeedLable.Caption:=IntToStr(100-ScrollBar1.Position);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
bmp1.FreeImage;
bmp2.FreeImage;
end;
end.
特别的是,TImage控件的大小不能比你的图片大,否则会闪烁(图片较大时闪的
更利害)。