2008. május 24., szombat

How to color TPanels on a form according to their Tag properties


Problem/Question/Abstract:

How to color TPanels on a form according to their Tag properties

Answer:

{ ... }
var
  ix: Integer;
  pnl: TPanel;
  { ... }

  for ix := 0 to ComponentCount - 1 do
  begin
    if Components[ix] is TPanel then
    begin
      pnl := TPanel(Components[ix]);
      case pnl.Tag of
        1: pnl.Color := clRed;
        2: pnl.Color := clBlue;
      else
        pnl.Color := clBtnFace;
      end;
    end;
  end;

Try placing the above code in a button OnClick event handler (having dropped some TPanels on the form with different Tag values).

Nincsenek megjegyzések:

Megjegyzés küldése