Page 1 of 1

Position text on node

Posted: Tue May 18, 2010 2:43 pm
by 10546756
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

Re: Position text on node

Posted: Wed May 19, 2010 12:03 pm
by yeray
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?

Re: Position text on node

Posted: Tue May 25, 2010 9:18 am
by 10546756
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

Re: Position text on node

Posted: Tue May 25, 2010 2:18 pm
by yeray
Hi Mikael,

You could add some offset:

Code: Select all

Node.Text.HorizOffset:=32;

Re: Position text on node

Posted: Tue May 25, 2010 5:15 pm
by 10546756
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

Re: Position text on node

Posted: Wed May 26, 2010 9:15 am
by yeray
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;