How to make a color change (yellow, blue, white) of an object every 5 seconds? shape, label
- fiveshape, label, timer - insolor
- Are you talking about a smooth transition? or just a color change? - Alex Kapustin
- Color Change - alic3s
|
2 answers
Here is a good option:
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.
- Horror! Why so long? - AseN
- The array is just fine. Klampitsa in the range of Low (color) .. High (color) is somewhat awkward, yes. - karmadro4
|