代码改变世界

如何在加载winform的时候自动改变treeview的指定根节点的字体颜色呢??

2009-05-21 09:38  观海看云  阅读(521)  评论(0编辑  收藏  举报

treeview1.Nodes[0].ForeColor = Color.Red;

 

 

 

private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            Color strColor;
            if (e.Node.Index % 2 == 0)  //判断结点
                strColor = Color.Red;
            else
                strColor = Color.Blue;
            e.Graphics.DrawString(e.Node.Text, this.Font, new SolidBrush(strColor), e.Bounds);
        }

另设置:
this.treeView1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;