Recent

Author Topic: TreeView  (Read 4880 times)

Emmanuel

  • New Member
  • *
  • Posts: 24
TreeView
« on: October 21, 2015, 07:48:54 am »
I wonder how to change the color of the text in a treeView.

 Thank you for your help ?  :)

balazsszekely

  • Guest
Re: TreeView
« Reply #1 on: October 21, 2015, 10:18:53 am »
You should set Options->tvoThemedDraw to False then draw each node as needed. For this use the OnCustomDrawItem event.
If you want to take custom drawing to another level, take a look at TVirtualStringTree/TVirtualDrawTree.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: TreeView
« Reply #2 on: October 21, 2015, 10:53:51 am »
That's a bit weird getmem.

I can change the plus, outline, edit, background colours, and i can display the font using every possible font property/style, but the one thing not cooperating is the component not 'using' the fontcolour for displaying ?

Someone happen to know if that's a deliberate limitation (e.g. delphi compatibility) ?

balazsszekely

  • Guest
Re: TreeView
« Reply #3 on: October 21, 2015, 11:58:28 am »
@molly
AFAIK TTreeView always draw the text using the color and font defined by the visual style(themed font). You have two choices change the theme or disable it. Feel free to check this(ComCtrls.pas). I find this issue irrelevant because I don't use the TTreeView(not very often to be more precise). I only wanted to help Emmanuel.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: TreeView
« Reply #4 on: October 21, 2015, 12:31:35 pm »
@GetMem
Ah, my apologies. You are correct.

Simply set the font colour as you wish and turn off tvoThemedDraw in ttreeview options.

balazsszekely

  • Guest
Re: TreeView
« Reply #5 on: October 21, 2015, 12:47:16 pm »
Quote
Simply set the font colour as you wish and turn off tvoThemedDraw in ttreeview options.
If all tree node should look the same then yes, this is the easiest solution.  I'm under the impression that the OP want to customize each node separately. Maybe I'm wrong.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: TreeView
« Reply #6 on: October 21, 2015, 01:25:09 pm »
Ah, you might be right about that GetMem.

Just in case:

Some things to add
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var i:integer;
  3. begin
  4.   TreeView1.Options := TreeView1.Options - [tvoThemedDraw];
  5.   For i := 1 to 10 do TreeView1.Items.Add(nil, 'item ' + IntToStr(i));
  6. end;
  7.  

and assign the OnDrawItemEvent:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  2.   Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
  3. begin
  4.   with Sender as TCustomTreeView do
  5.     if odd(Node.Index)
  6.     then Canvas.Font.Color:= clRed
  7.     else Canvas.Font.Color:= clGreen;
  8. end;
  9.  

Or something similarish...

 

TinyPortal © 2005-2018