phadaphunk
phadaphunk

Reputation: 13313

Change part of node color

I have a TreeView and I need each node to support multi color text.

I don't really know how to put it into words so searching for an answer is a little difficult.

enter image description here

The picture above represents what I want to have but the only difference is I don't want rectangles I want the text inside to be orange. So part of the Node.Text would be of the default color and the rest would be orange. I don't know if this changes anything but each node would have two words the first one would be in default color and the second one would be orange. So I don't need to split one word into two colors.

Any idea where I should start looking ?

Upvotes: 3

Views: 382

Answers (2)

kol
kol

Reputation: 28728

Check out the TreeView.DrawNode event. There is an example in the documentation.

Upvotes: 1

Paul Sasik
Paul Sasik

Reputation: 81547

You need to owner-draw the text. Take a look at the TreeView.DrawNode event and specifically using the OwnerDrawText value of the TreeViewDrawMode enumeration.

From the link:

Use this event to customize the appearance of nodes in a TreeView control using owner drawing.

This event is raised only when the DrawMode property is set to TreeViewDrawMode values of OwnerDrawAll or OwnerDrawText. The following table indicates how the TreeNode can be customized when the DrawMode property is set to these values.

Upvotes: 1

Related Questions