Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a number on a TShape Component?

I have a TShape Component. I need to load it dynamically and I need to place a number on that TShape. If anyone knows the way - please suggest it to me.

Thanks Rakesh

like image 682
Rakesh Devarasetti Avatar asked Oct 16 '25 13:10

Rakesh Devarasetti


2 Answers

You can use the Canvas property of the TShape component to draw the number, to access this protected property you must create descendent class of TShape and publish that property or just use a interposer class.

type
  TShape = class(ExtCtrls.TShape); //interposer class

  TForm1 = class(TForm)
    Shape1: TShape;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
    Shape1.Canvas.Font.Name :='Arial';// set the font 
    Shape1.Canvas.Font.Size  :=20;//set the size of the font
    Shape1.Canvas.Font.Color:=clBlue;//set the color of the text
    Shape1.Canvas.TextOut(10,10,'1999');
end;
like image 199
RRUZ Avatar answered Oct 19 '25 11:10

RRUZ


Place a TLabel above it and make its background transparent (Transparent = True). Edit text alignment if needed (Alignment := taCenter)

like image 26
Kromster Avatar answered Oct 19 '25 11:10

Kromster