0

Как сделать смену цвета ( желтый, голубой, белый ) объекта каждые 5 секунд? shape, label

3
  • 5
    shape,label,timer
    – insolor
    31 мар 2012 в 18:42
  • вы про плавный переход ? или просто смена цвета ? 31 мар 2012 в 22:26
  • Смена цвета
    – alic3s
    1 апр 2012 в 6:57

2 ответа 2

0

Вот неплохой вариант:

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;
0
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.
2
  • Ужас! Зачем так длинно?
    – AseN
    14 апр 2012 в 15:00
  • Массив-то как раз хорошо. Клампится в диапазон Low(color)..High(color) несколько неуклюже, это да.
    – karmadro4
    14 апр 2012 в 15:46

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.