unit ImagePanel; interface uses Windows,ExtCtrls,Graphics,Classes,Controls; type TImagePanel=class(TCustomPanel) private FPicture: TPicture; FAutoSize: Boolean; FTransParent: boolean; procedure setPicture(const Value: TPicture); procedure SetAutoSize(const Value: Boolean); reintroduce; procedure setTransparent(const Value: boolean); procedure setFont(const value:TFont); procedure setCaption(const value:tCaption); procedure setAlignMent(const value:TAlignment); procedure pictureChanged(Sender:TObject); public constructor Create(Aowner:TComponent);override; destructor Destroy();override; protected procedure Paint;override; published property picture:TPicture read FPicture write setPicture; property AutoSize:Boolean read FAutoSize write SetAutoSize; property Transparent:boolean read FTransParent write setTransparent; property Font write setFont; property Caption write setCaption; property alignment write setAlignMent; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples',[TImagePanel]); end; { TImagePanel } constructor TImagePanel.Create(Aowner: TComponent); begin inherited Create(Aowner); FPicture:=TPicture.Create(); FPicture.OnChange:=pictureChanged; rePaint; end; destructor TImagePanel.destroy; begin FPicture.Free(); FPicture:=nil; inherited; end; procedure TImagePanel.Paint; const alignments:array[TAlignment] of Longint=(DT_LEFT,DT_RIGHT,DT_CENTER); var Flags:LongInt; Rect:TRect; FontHeight:Integer; begin inherited; Canvas.Brush.Style:=bsClear ; Canvas.Font.Assign(Font); if Assigned(FPicture.Graphic) then begin if fAutosize then begin width:=FPicture.Width; Height:=FPicture.Height; end; if FPicture.Graphic.Transparent<>FTransParent then FPicture.Graphic.Transparent:=FTransParent; Canvas.StretchDraw(ClientRect,FPicture.Graphic); end else begin Canvas.Brush.Color:=color; Canvas.FillRect(ClientRect); end; if Caption<>'' then begin rect:=GetClientRect; FontHeight:=Canvas.TextHeight('W') ; rect.top:=((Rect.Bottom+rect.Top)-fontHeight)div 2; rect.Bottom:=rect.Top+fontheight; flags:=DT_EXPANDTABS or DT_VCENTER or alignments[alignment]; Flags:=DrawTextBiDiModeFlags(flags) ; DrawText(Canvas.Handle,PChar(caption),-1,rect,Flags); end; end; procedure TImagePanel.pictureChanged(Sender: TObject); begin rePaint; end; procedure TImagePanel.setAlignMent(const value: TAlignment); begin inherited AlignMent:= value; repaint; end; procedure TImagePanel.SetAutoSize(const Value: Boolean); begin FAutoSize := Value; rePaint; end; procedure TImagePanel.setCaption(const value: tCaption); begin inherited Caption:=value; repaint; end; procedure TImagePanel.setFont(const value: TFont); begin inherited font:=value ; repaint; end; procedure TImagePanel.setPicture(const Value: TPicture); begin FPicture.Assign(Value); repaint; end; procedure TImagePanel.setTransparent(const Value: boolean); begin FTransParent := Value; repaint; end; end.