跑马灯的实现

昨天去火车站买票,看到火车站上的跑马灯文字提示很好玩,就自己编个小程序娱乐了一下~~

很简单的代码。。。

 

 

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1
= class(TForm)
lbl1: TLabel;
lbl2: TLabel;
tmr1: TTimer;
procedure FormCreate(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
procedure FormDblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
lbl1.Left :
= 330;
lbl2.Left :
= 330;
lbl1.Top :
= 160;
lbl2.Top :
= 160;

end;

procedure TForm1.FormDblClick(Sender: TObject);
begin
lbl1.Caption :
= InputBox('输入:','请输入跑马灯的文字:','我是跑马灯,呵呵呵呵');
lbl2.Caption :
= lbl1.Caption;
end;

procedure TForm1.tmr1Timer(Sender: TObject);
begin

if lbl1.Left <= 0 then //如果到了边界,label2显示,并开始移动
begin
lbl2.Visible :
= true;
lbl2.Left :
= lbl2.Left - 1;
end
else
begin
lbl2.Visible :
= false; //如果还没到边界,label2不显示,初始化label的边界
lbl2.Left :
= Form1.Width;
end;

if (lbl1.Left + lbl1.Width) < 0 then //如果移动到了不显示的位置,从label2的当前位置继续移动
lbl1.Left :
= lbl2.Left;

lbl1.Left :
= lbl1.Left - 1;
end;

end.

 

 

 

posted @ 2010-07-10 14:07  Delcpp  阅读(671)  评论(0编辑  收藏  举报