delphi4arab منتديات دلفي للعرب

نسخة كاملة : تغيير الوان shapeضمن التايمر
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
الصفحات : 1 2
السلام عليكم ‏‏‏
ما هي اسهل طريقة لتغيير لون 4 shapeبالتتابع من خلال انترفال تايمر واحد
دلفي xe2

كود :
unit Unit15; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls; type TForm15 = class(TForm) Shape1: TShape; Timer1: TTimer; procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form15: TForm15; c : array [1..4] of Tcolor = (clred,clblue,clgreen,clwhite); i : integer=1; implementation {$R *.dfm} procedure TForm15.Timer1Timer(Sender: TObject); begin shape1.Brush.Color:=c[i]; i:=i+1; if i=5 then i:=1; end; end.
اخي الكريم لدي اربع shape على بانل كيف يتغير لونهم واحد تلو الاخر الى اللون الاخضر من ضمن نفس الانترفال اي قبل ان ينتهي اول زمن
يمكن من ضمن نفس الانترفال ان تستعمل دالة sleep ولكنها ليست بالحل الامثل لأنها تسبب في حدوث بطء في التنفيذ

مثال
ضع قيمة الانترفال 2500

كود :
Shape1.Brush.Color := clGreen; Shape1.Repaint; sleep(500); Shape2.Brush.Color := clGreen; Shape2.Repaint; sleep(500); Shape3.Brush.Color := clGreen; Shape3.Repaint; sleep(500); Shape4.Brush.Color := clGreen; Shape4.Repaint; sleep(500); Shape1.Brush.Color := clWhite; Shape2.Brush.Color := clWhite; Shape3.Brush.Color := clWhite; Shape4.Brush.Color := clWhite;
rabihpascal كتب :اخي الكريم لدي اربع shape على بانل كيف يتغير لونهم واحد تلو الاخر الى اللون الاخضر من ضمن نفس الانترفال اي قبل ان ينتهي اول زمن



استخدم هذا الكود

في اي حدث


كود :
var i : Integer; begin btn2.Enabled := False; for i := 0 to 40 do begin Application.ProcessMessages; Sleep(2); case i of 0: begin shp1.Brush.Color := clGreen; shp2.Brush.Color := clWhite; shp3.Brush.Color := clWhite; shp4.Brush.Color := clWhite; end; 10: begin shp1.Brush.Color := clWhite; shp2.Brush.Color := clGreen; shp3.Brush.Color := clWhite; shp4.Brush.Color := clWhite; end; 20: begin shp1.Brush.Color := clWhite; shp2.Brush.Color := clWhite; shp3.Brush.Color := clGreen; shp4.Brush.Color := clWhite; end; 30: begin shp1.Brush.Color := clWhite; shp2.Brush.Color := clWhite; shp3.Brush.Color := clWhite; shp4.Brush.Color := clGreen; end; end; end; btn2.Enabled := True; end;
كود :
btn2.Enabled := False;


هذه ما قبل لاجراء

كود :
btn2.Enabled := True;

هذه ما بعد الاجراء
السلام عليكم
لماذا لا تقسم الانترفال احسن ان كان 1000 تقسمه على 4 ؟ !!
السلام عليكم اولا اشكر الجميع لا يصح تقسيم الانترفال لانه يترافق مع ملف موسيقي بنفس الطول اما بخصوص sleepفانها تتسبب بتقطيع الصوت واحيانا اعتراض
يمكنك استخدام الـ thread وضح بالتفصيل ما تحاول فعله ما ترغب الوصول اليه محاولتك المشكلة و ما الى ذلك و ستجد اجابة ان شاء الله ...
الصفحات : 1 2