Как сделать смену цвета ( желтый, голубой, белый ) объекта каждые 5 секунд? shape, label
2 ответа
Вот неплохой вариант:
var counter:integer = 0;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(i);
case i of
1:shape1.Brush.Color:=rgb(255,255,0);
2:shape1.Brush.Color:=rgb(0,190,255);
3:begin shape1.Brush.Color:=rgb(255,255,255); i:=0;end;
end;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Shape1: TShape;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i: integer;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
const
color: array [1..3] of tcolor = (
clYellow,
clBlue,
clWhite
);
begin
if i=3 then
begin
i:=1;
end
else
begin
i:=i+1;
end ;
Shape1.Brush.Color:=color[i];
end;
end.
-
-
Массив-то как раз хорошо. Клампится в диапазон Low(color)..High(color) несколько неуклюже, это да. 14 апр 2012 в 15:46