unit GraphicButton;
interface
uses
SysUtils, Classes, Controls, Graphics;
type
TGraphicButton =
class(TGraphicControl)
private
FBild: TBitmap;
FBildClick: TBitmap;
procedure SetBild(Value: TBitmap);
procedure SetBildClick(Value: TBitmap);
protected
procedure Paint;
Override;
procedure Click;
public
property Canvas;
constructor Create(AOwner: TComponent);
published
property Caption;
property Color;
property Bild: TBitmap
read FBild
write SetBild;
property BildClick: TBitmap
read FBildClick
write SetBildClick;
property Font;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Eigene', [TGraphicButton]);
end;
constructor TGraphicButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBild := TBitmap.Create;
FBildClick := TBitmap.Create;
end;
procedure TGraphicButton.Paint;
begin
inherited;
if Font <>
nil then
Canvas.Font := Font;
if csDesigning
in ComponentState
then
begin
Canvas.Brush.Style := bsClear;
Canvas.Pen.Style := psDashDot;
Canvas.Rectangle(0, 0, width, height);
Canvas.TextOut((width - Canvas.TextWidth(Caption))
div 2,(height - Canvas.TextHeight(Caption))
div 2, Caption);
end
else
begin
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Style := psSolid;
Canvas.Brush.Color := Color;
Canvas.Rectangle(0, 0, width, height);
if Assigned(FBild)
then
Canvas.Draw(0, 0, FBild);
Canvas.Brush.Style := bsClear;
Canvas.TextOut((width - Canvas.TextWidth(Caption))
div 2,(height - Canvas.TextHeight(Caption))
div 2, Caption);
end;
end;
procedure TGraphicButton.Click;
begin
end;
procedure TGraphicButton.SetBild(Value: TBitmap);
begin
FBild.Assign(Value);
Repaint;
end;
procedure TGraphicButton.SetBildClick(Value: TBitmap);
begin
FBildClick.Assign(Value);
Repaint;
end;
end.