1

I'm using this TreeViewMS implementation so that the users can have multiselection feature but I found something isn't working properly today. If I set TreeNode.ForeColor property to say, Color.Red, and put focus on that node, its color gets back to default color (Black) soon as I get the mouse out of that node. How do I workaround this? I've been looking for an event to set the TreeNode.ForeColor to my custom one soon as the node lost focus if that node match the needs to change its color. Is there such an event?

1
  • Is HideSelection true? Commented Aug 14, 2016 at 7:36

1 Answer 1

1

The issue is in TreeViewMS class. Look at removePaintFromNodes method:

protected void removePaintFromNodes() { if (m_coll.Count==0) return; TreeNode n0 = (TreeNode) m_coll[0]; Color back = n0.TreeView.BackColor; Color fore = n0.TreeView.ForeColor; foreach ( TreeNode n in m_coll ) { n.BackColor = back; n.ForeColor = fore; } } 

This method resets the backcolor and the forecolor to the treeview default.

If you remove this method, it will retains the forecolor of the node when you click on another node, but when the node is selected, it will use the default forecolor for selected node.

To fix that, you can draw the node text yourself by doing this:

treeViewMS1.DrawMode = TreeViewDrawMode.OwnerDrawText; treeViewMS1.DrawNode += TreeViewMS1_DrawNode; 

And this:

private void TreeViewMS1_DrawNode(object sender, DrawTreeNodeEventArgs e) { TextRenderer.DrawText(e.Graphics, e.Node.Text, e.Node.NodeFont, e.Bounds, e.Node.ForeColor, TextFormatFlags.GlyphOverhangPadding); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.