Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Shape beschriften oder alternative? (https://www.delphipraxis.net/35345-shape-beschriften-oder-alternative.html)

DerNewbie 5. Dez 2004 22:06


Shape beschriften oder alternative?
 
Hi,

gibt es eine möglichkeit einem Shape, irgendwie eine Caption zu geben, ohne z.b ein zusätzliches
transparentes Label über das Shape zu legen, da ich Shape und Text als Einheit brauche. Welche alternative möglichkeit gäbe es denn, soetwas zu realisieren.


Gruß DerNewbie

Niko 7. Dez 2004 15:57

Re: Shape beschriften oder alternative?
 
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;


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:01 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz