我要动态的创建一个panel控件,在panel上还有一个image控件,是和panel一起创建的,在我写onclickimage事件时,要使它所在的panel控件有一个变化,比如:变换颜色,在这里我不太会,请谁来帮我想想我该怎么做呢
我写的一段代码是这样的
var  btn:array of tpanel;
    image:array of timage;
    i,icount:integer;
begin
  icount:=5;
  setlength(btn,icount);
  setlength(image,icount);
  for i:=0 to icount-1 do
  begin
     btn[i]:=tpanel.Create(self);
     btn[i].Parent:=scrollbox1;
     btn[i].Left:=i*100;
     btn[i].Top:=100;
     btn[i].Width:=60;
     btn[i].Height:=60;
     btn[i].caption:=inttostr(i);
     btn[i].Tag:=i;
     image[i]:=timage.Create(self);
     image[i].Parent:=btn[i];
     image[i].Picture.LoadFromFile('F:\工作\新建文件夹\fileopen.bmp');
     image[i].Align:=alright;
     image[i].Proportional:=true;
     image[i].Center:=true;
     image[i].Stretch:=false;
     image[i].tag:=i;
     image[i].OnClick:=imageclick;procedure tfrm_dcsy.imageclick(sender:tobject);
begin
if sender is timage then
他的父控件变颜色,这里该怎么写呢??end;请各位帮我想一想

解决方案 »

  1.   

    procedure tfrm_dcsy.imageclick(sender:tobject);
    begin
    if sender is timage then
    btn[0].color:=clred;end;
      

  2.   

    你写的是什么啊,我要是想让某个固定的panel变颜色还用发这个帖子吗?我是想让所点击的image控件的父控件也就是他下面的panel变色,而不是固定的就第一个变色
      

  3.   

    第二版出来了
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        ScrollBox1: TScrollBox;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure imageClick(Sender:TObject);
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    var
        btn:array of tpanel;
        image:array of timage;
    procedure TForm1.Button1Click(Sender: TObject);
    var
        i,icount:integer;
    begin
      icount:=5;
      setlength(btn,icount);
      setlength(image,icount);
      for i:=0 to icount-1 do
      begin
         btn[i]:=tpanel.Create(self);
         btn[i].Parent:=scrollbox1;
         btn[i].Left:=i*100;
         btn[i].Top:=100;
         btn[i].Width:=60;
         btn[i].Height:=60;
         btn[i].caption:=inttostr(i);
         btn[i].Tag:=i;
         image[i]:=timage.Create(self);
         image[i].Parent:=btn[i];
         image[i].Tag :=I;//我新增的 
         image[i].Picture.LoadFromFile('d:\ms.bmp');
         image[i].Align:=alright;
         image[i].Proportional:=true;
         image[i].Center:=true;
         image[i].Stretch:=false;
         image[i].tag:=i;
         image[i].OnClick:=imageclick;
      end;end;procedure TForm1.imageClick(Sender: TObject);
    begin
      Case (sender as timage).tag of
        0:begin
            btn[0].color:=clred;
          end;
        1:begin
            btn[1].color:=clYellow;
          end;
        2:begin
            btn[2].color:=clLime;
          end;
        3:begin
            btn[3].color:=clGreen;
          end;
        4:begin
            btn[4].color:=clCaptionText ;
          end;
      end;
    end;end.