Position text on node

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Position text on node

Post by Lenfors » Tue May 18, 2010 2:43 pm

When I assign icons (32*32) to my nodes the text is not repositioned at the right of the icon, its written right over it!? How can I position the text?

Regards, Mikael

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Position text on node

Post by Yeray » Wed May 19, 2010 12:03 pm

Hi Mikael,

I'm trying to reproduce the problem with the following code:

Code: Select all

uses TeeTree, PNGImage;

procedure TForm1.FormCreate(Sender: TObject);
var Tree1: TTree;
    TreeNodeShape1: TTreeNodeShape;
begin
  Tree1:=TTree.Create(self);
  Tree1.Parent:=Self;
  Tree1.Align:=alClient;

  TreeNodeShape1:=TTreeNodeShape.Create(self);
  TreeNodeShape1.Text.Text:='my first node';
  TreeNodeShape1.Tree:=Tree1;
  TreeNodeShape1.Image.LoadFromFile('C:\tmp\32_button_red.png');
//  TreeNodeShape1.ImageAlignment:=iaCenter;
end;
Could you please explain what would you expect to obtain or what modifications are needed to reproduce the problem?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Re: Position text on node

Post by Lenfors » Tue May 25, 2010 9:18 am

I use the following code to create then nodes:

Node := Tree.AddRootObject('Group ' + intToStr(I), TNodeData.Create);
Node.AutoSize := True;
Node.Height := 34;
Node.Font.Size := 12;
Node.Border.Hide;
Node.ImageListIndex := 0;

After some testing I found that it's the "Node.Height := 34;" command that is the problem! When I comment this line the text is positioned right of the icon.

The icons are 32*32 so if I don't set the hight to 34 there is no space between them!.

Mikael

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Position text on node

Post by Yeray » Tue May 25, 2010 2:18 pm

Hi Mikael,

You could add some offset:

Code: Select all

Node.Text.HorizOffset:=32;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Lenfors
Newbie
Newbie
Posts: 49
Joined: Thu Sep 20, 2007 12:00 am

Re: Position text on node

Post by Lenfors » Tue May 25, 2010 5:15 pm

No, the HorizOffset and VertOffset only positions the text within the node! I want to increase the distance between two nodes in Y-direction. As default the icons added to the nodes are positioned exactly below each other!

Regards, Mikael

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Position text on node

Post by Yeray » Wed May 26, 2010 9:15 am

Hi Mikael,

So the problem may be in the height? Could you please try the following?

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var t: Integer;
begin
  with Tree1.AddRoot('Root') do
  begin
    Tree1.Items[0].Height:=32;
    Tree1.Items[0].Width:=Form1.Canvas.TextWidth(Tree1.Items[0].Text.Text);
    for t:=1 to 20 do
    begin
      AddChild('Node '+IntToStr(t));
      Tree1.Items[t].Height:=32;
      Tree1.Items[t].Width:=Form1.Canvas.TextWidth(Tree1.Items[t].Text.Text);;
    end;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply