如何在 TShape 组件上写数字?

Rak*_*tti 4 delphi delphi-7

我有一个 TShape 组件。我需要动态加载它,并且需要在 TShape 上放置一个数字。如果有人知道方法 - 请向我推荐。

谢谢拉克什

RRU*_*RUZ 5

您可以使用组件的 Canvas 属性TShape来绘制数字,要访问此受保护的属性,您必须创建 TShape 的后代类并发布该属性,或者仅使用插入器类

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;
Run Code Online (Sandbox Code Playgroud)