Einzelnen Beitrag anzeigen

Niko

Registriert seit: 23. Jun 2003
416 Beiträge
 
Delphi 2006 Professional
 
#2

Re: Shape beschriften oder alternative?

  Alt 7. Dez 2004, 15:57
Hi,

am einfachsten dürfte es wohl sein, wenn du dir dafür eine eigene Shape-Komponente bastelst:
Delphi-Quellcode:
unit ExtShape;

interface

uses
  ExtCtrls, Graphics;

type TExtShape = class(TShape)
  protected
    procedure Paint; override;
  published
    property Caption;
    property Font;
  end;

implementation

{ TCaptionShape }

procedure TExtShape.Paint;
begin
  inherited Paint;
  Canvas.Font := Font;
  Canvas.Brush.Style := bsClear;
  with Canvas do
  begin
    TextOut((Width - TextWidth(Caption)) div 2,
      (Height - TextHeight(Caption)) div 2, Caption);
  end;
end;
Das ganze kannst du dann entweder in die Komponentenpalette aufnehmen oder direkt einsetzen:
Delphi-Quellcode:
with TExtShape.Create(Form1) do
begin
  parent := Form1;
  Font.Height := 30;
  Caption := 'Hallo!';
end;
"Electricity is actually made up of extremely tiny particles called electrons, that you cannot see with the naked eye unless you have been drinking." (Dave Barry)
  Mit Zitat antworten Zitat