本人初写了一个控件,注要是在扩展TPanel控件,在其上加入一个图像。我的思路是: 
   1.给TPanel一个panPciture:TPicture属性。
   2.当给panPicture加入图形时(ico文件)。创建一个TImage控件,它的Parent为TPanel.
   问题:控件在设计时,可以根据panPicture的图形,在新的控件中显示图形,但在运行时,图形不显示了。不知是何原因,还请各位能提点一下我。
  下面是第2的代码
procedure TImgText.SetPanPicture(const Value: TPicture);
begin
  if FImage=nil then
    FImage:=TImage.Create(self);
  FImage.Parent:=Self;
  FImage.Left:=(self.Width-FImage.Width) div 2;
  FImage.AutoSize:=True;
  if Value<>nil then
    FImage.Picture.Assign(Value);
  self.Caption:='';
end;

解决方案 »

  1.   

    是不是因为文件类型影响,你试试用bmp的
      

  2.   

    你把const Value: TPicture改成var Value: TPicture试试呢
      

  3.   

    这样不更好么
    放一panel到form上-->在panel 上放一个image -->点击panel
    -->component-->create component template或者把TPicture该为image不更容易实现
    constructor Trtuimagexs.Create(Owner: TComponent);
    begin
     inherited;
     Fimage :=Timage.Create(self);
     Fimage.Parent:=self;
     Fimage.Left:=1;
     Fimage.Top:=5;
     Fimage.Height:=30;
     Fimage.Width:=60;
     Fimage.Stretch:=true;
     Fimage.Transparent:=true;
     Fimage.ShowHint:=true;
    end;
    Destructor Trtuimagexs.destroy;
    begin
     freeandnil(Fimage);
     inherited Destroy;
    end;