TreeView Text Modification

How do I change The Text Properties in a TreeView. For example I would like the root nodes to be bold. Is it posible to change font types, colors or sizes etc.

Comments

  • : How do I change The Text Properties in a TreeView. For example I would like the root nodes to be bold. Is it posible to change font types, colors or sizes etc.
    :
    You need to use the OnCustomDrawItem() event for that. Here is a small code, which draws all root nodes bold and italic. You can modify this code to add colors or other styles.
    [code]
    procedure TForm1.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
    Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
    var PaintImages, DefaultDraw: Boolean);
    begin
    with TreeView1.Canvas do begin // use the canvas of the treeview and not the form's canvas
    if Node.Level = 0 then // root nodes have a level of 0
    Font.Style := [fsBold, fsItalic]
    else // all other have higher level properties
    Font.Style := [];
    DefaultDraw := true; // let the treeview do the drawing with your selected properties
    end;
    end;
    [/code]
    I've included italic so show you how to code various font-styles in one line. The properties are detailed in the help-files, just like a description of the event itself.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion