Page 1 of 1

Query related to rectangle tool children.

Posted: Tue May 19, 2020 12:30 pm
by 9526439
Hi,

We are currently using Active X 2018. We have added a rectangle tool and are able to add its text, font and children etc. But we are unable to add text to its children.

Following is the code we are currently using

Code: Select all

ui->mChart->Tools()->Add(tcRectangle);
ui->mChart->Tools()->Items(0)->asRectangle()->SetText("Technology - Software - Infrastructure");
ui->mChart->Tools()->Items(0)->asRectangle()->Shape()->Font()->SetSize(12);
ui->mChart->Tools()->Items(0)->asRectangle()->Shape()->SetTransparency(30);
ui->mChart->Tools()->Items(0)->asRectangle()->SetAllowDrag(false);
ui->mChart->Tools()->Items(0)->asRectangle()->SetAllowResize(false);
ui->mChart->Tools()->Items(0)->asRectangle()->SetAutoSize(true);

ui->mChart->Tools()->Items(0)->asRectangle()->Shape()->Children()->Add();
ui->mChart->Tools()->Items(0)->asRectangle()->Shape()->Children()->Item(0)->Shape()->Font()->SetSize(16);
Please guide us as to how we could add text to the children elements too. Our target is to view different text with different font size and colors.

Regards,
Amol

Re: Query related to rectangle tool children.

Posted: Fri May 22, 2020 9:09 am
by yeray
Hello Amol,

You need to cast the Shape child to TCustomTextShape to access the Text property. Ie, this in Delphi:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TRectangleTool(Chart1.Tools.Add(TRectangleTool)) do
  begin
    Text:='Rectangle Tool';
    Shape.Transparency:=10;
    Shape.Font.Color:=clRed;
    Shape.Font.Style:=Shape.Font.Style+[fsBold];
    AutoSize:=True;
    Left:=100;
    Top:=100;

    with Shape.Children.Add do
    begin
      Shape.Font.Color:=clGreen;
      TCustomTextShape(Shape).Text:='Children';
    end;
  end;
end;
Project1_2020-05-22_11-07-09.png
Project1_2020-05-22_11-07-09.png (4.83 KiB) Viewed 4598 times

Sorry, I thought it was VCL. Let me check if this property is mapped in ActiveX.

Re: Query related to rectangle tool children.

Posted: Fri May 22, 2020 10:41 am
by yeray
Hello,

Indeed the Text property isn't accessible by code. I've added i to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=2330