每个Label的Click事件都可以这么写: for i := 0 to panel.controlcount - 1 do if panel.controls[i] is TLabel then TLabel(panel.controls[i]).Color := clBlack; (Sender as TLabel).Color := clRed;
var i:integer; begin for i:=0 to panel1.ComponentCount-1 do if panel1.Components[i] is TLabel then TLabel(panel1.Components[i]).Color:=clblack; if Sender is TLabel then TLabel(Sender).Color:=clRed; end;
不要全部设置,这样不仅效率低,而且闪烁!for i :=0 to panel.controlscount-1 do begin if panel.controls[i] as Tlable.color <>clblack then panel.controls[i] as Tlable.color:=clblack; end;sender as Tlable..color:=clred;
for i := 0 to panel.controlcount - 1 do
if panel.controls[i] is TLabel then
TLabel(panel.controls[i]).Color := clBlack;
(Sender as TLabel).Color := clRed;
i:integer;
begin
for i:=0 to panel1.ComponentCount-1 do
if panel1.Components[i] is TLabel then
TLabel(panel1.Components[i]).Color:=clblack;
if Sender is TLabel then TLabel(Sender).Color:=clRed;
end;
FindComponent(TLabl(Sender).Name).color := clred;
if panel.controls[i] as Tlable.color <>clblack then
panel.controls[i] as Tlable.color:=clblack;
end;sender as Tlable..color:=clred;