有一个简单的办法:
1、在窗体中放6个TImage控件,并为它们分别设置相应的Picture属性,放置不同的图片内容;
2、将6个TImage控件的大小调整为一致;
3、将6个TImage控件的Visible属性都设置为False;
4、在单元的Private段申明一个变量FCur:Integer;
5、在Timer的OnTimer事件中写代码,大意如下:
Image1.visiable:=true;
Image2.visiable:=false;
示例代码如下:(纯手工打造啊!)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, jpeg;
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
FCur:Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
FCur:=0;
for i:=1 to 6 do
begin
//设置6个Image控件的上、左、高、宽。
//它们的名字需要为Image1~Image6
(FindComponent('Image'+IntToStr(i)) as TImage).Visible:=false;
(FindComponent('Image'+IntToStr(i)) as TImage).Left:=10;
(FindComponent('Image'+IntToStr(i)) as TImage).Top:=10;
(FindComponent('Image'+IntToStr(i)) as TImage).Width:=100;
(FindComponent('Image'+IntToStr(i)) as TImage).Height:=100;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i:integer;
begin
inc(FCur);
for i:=1 to 6 do
begin
//先把所有Image隐藏
(FindComponent('Image'+IntToStr(i)) as TImage).Visible:=false;
end;
//显示当前的Image
(FindComponent('Image'+IntToStr(FCur)) as TImage).Visible:=true;
if FCur>=6 then
FCur:=0;
end;
end.
温馨提示:内容为网友见解,仅供参考