Mirror

Color all controls on a form at runtime (Views: 708)


Problem/Question/Abstract:

I want to color form controls at runtime without knowing beforehand how many and what controls there are.

Answer:

type
  TControlCracker = class(TControl);

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to ComponentCount - 1 do
    if Components[I] is TControl then
      TControlCracker(Components[I]).Color := clLime;
end;

<< Back to main page