tag 用法
界面:
需取消各panel的背景色设置,如:panel1.parentBackgroud:false;
源代码:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; Panel2: TPanel; Panel3: TPanel; Panel4: TPanel; Panel5: TPanel; Label1: TLabel; Button1: TButton; Edit1: TEdit; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; varpan:array[1..5] of tpanel; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin varpan[strtoint(edit1.Text)].Color:=clred; end; procedure TForm1.FormCreate(Sender: TObject); var i:integer; begin varpan[1]:=panel1; varpan[2]:=panel2; varpan[3]:=panel3; varpan[4]:=panel4; varpan[5]:=panel5; for i:=1 to 5 do varpan[i].Tag:=i; end; end.