Nie działa bo widocznie nie zrobiłeś tego tak jak trzeba.
Ehh... naucz się pisać komponenty (chociażby takie proste), przyda ci się to. Tym razem zrobiłem to za ciebie, żeby ci pokazać, że działa. Zapisz sobie ten kod do pliku *.pas i zainstaluj komponent.
unit BmpPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, ExtCtrls;
type
TBmpPanel = class (TPanel)
private
FBitmap: TBitmap;
procedure SetBitmap(Value: TBitmap);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Bitmap: TBitmap read FBitmap write SetBitmap;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TBmpPanel]);
end;
{ TBmpPanel }
{------------------------------------------------------------------------------}
procedure TBmpPanel.SetBitmap(Value: TBitmap);
begin
try
FBitmap.Assign(Value);
Repaint;
except
FBitmap := nil;
end;
end;
{------------------------------------------------------------------------------}
procedure TBmpPanel.Paint;
var
LeftPos: Integer;
begin
inherited;
with Canvas do
begin
if FBitmap <> nil then
StretchDraw(Rect(1, 1, Width -1, Height -1), FBitmap);
// narysowalismy bitmape, wiec musimy od nowa narysowac text
case Alignment of
taCenter: LeftPos := Width shr 1 - TextWidth(Caption) shr 1;
taRightJustify: LeftPos := Width - 2 - TextWidth(Caption);
else LeftPos := 2;
end;
Brush.Style := bsClear;
// jesli ma byc sama bitmapa to nie rysujemy tekstu
TextOut(LeftPos, (Height - TextHeight('Z')) div 2, Caption);
end;
end;
{------------------------------------------------------------------------------}
constructor TBmpPanel.Create(AOwner: TComponent);
begin
inherited;
FBitmap := TBitmap.Create;
DoubleBuffered := True;
end;
{------------------------------------------------------------------------------}
destructor TBmpPanel.Destroy;
begin
FBitmap.Free;
inherited;
end;
end.
I jak nie działa jak działa :-[ tylko trzeba dobrze zrobić.