你试一下跟踪,将发现Paint事件根本没有载入图片
其实你可以采用下面的程序来实现你的控件功能,就可以了:
var CDC:HDC;
  a:TCanvas;
  bit:TBitmap;
begin
  CDC:=getdc(Panel1.Handle);
  a:=TCanvas.Create;
  bit:=TBitmap.Create;
  bit.LoadFromFile('c:\windows\tiles.bmp');
  a.Handle:=cdc;
  a.Draw(0,0,bit);
end;

解决方案 »

  1.   

    另外给你一段其他的参考例程:
    unit TilePanel;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls;type
      TTilePanel = class(TPanel)
      private
        FTile: TPicture;
        procedure TileChanged(Sender: TObject);
        procedure SetTile(Value: TPicture);
      protected
        procedure Paint; override;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        property Tile: TPicture read FTile write SetTile;
      end;procedure Register;implementationconstructor TTilePanel.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);  FTile := TPicture.Create;
      FTile.OnChange := TileChanged;
    end;destructor TTilePanel.Destroy;
    begin
      FTile.Free;  inherited Destroy;
    end;procedure TTilePanel.TileChanged(Sender: TObject);
    begin
      Invalidate;
    end;procedure TTilePanel.SetTile(Value: TPicture);
    begin
      FTile.Assign(Value);
    end;procedure TTilePanel.Paint;
    var
      x, y: Integer;
    begin
      inherited Paint;  if (FTile.Graphic=nil) and (FTile.Width=0) and (FTile.Height=0) then
      begin
        y := 0;
        while y=Height do
        begin
          x := 0;
          while x=Width do
          begin
            Canvas.Draw(x, y, FTile.Graphic);
            Inc (x, FTile.Width);
          end;
          Inc (y, FTile.Height);
        end;
      end;
    end;procedure Register;
    begin
      RegisterComponents('MyPanel', [TTilePanel]);
    end;end.
      

  2.   

    to forgot
      你的发表的控件同样的不能显示
      

  3.   

    是啊,你的代码同样[当然地]不能显示图片。你都没有把图片和panel关联起来,好像捉迷藏似的。
      

  4.   

    这个问题我自己好象琢磨出来了,在paint事件中要重新draw一下picture.graphic的。谢谢大家的热情了