结点选中时,原有的颜色不被覆盖

把treeview的DrawMode属性设置成OwnerDrawText,然后在DrawNode事件里自己画:
        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            if ((e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected)
            {
                e.Graphics.FillRectangle(new SolidBrush(Color.Red), e.Bounds);
                e.Graphics.DrawString(e.Node.Text,treeView1.Font,new SolidBrush(Color.White),e.Bounds.Location);
            }
            else
            {
                e.DrawDefault = true;
            }
        }
    }

 

posted @ 2013-07-03 16:32  单单的风  阅读(194)  评论(0编辑  收藏  举报