简体   繁体   中英

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.

在此输入图像描述

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 ?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM