如题,,,用TreeNode的ForeColor属性是不行的,因为是选中的节点,而不是所有的节点,谢谢大家帮忙,,,在线等

解决方案 »

  1.   

    Tree1.SelectedNode.ForColor = Color.Black
      

  2.   

    TreeView1.SelectedNode.ForeColor 
      

  3.   

    public Form1()
            {
                InitializeComponent();
                treeView1.HideSelection = true;
            }TreeNode preNode = null;
            private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
            {            if (preNode != null)
                    preNode.ForeColor = Color.Black;
                e.Node.ForeColor = Color.Blue;
                preNode = e.Node;
            }
      

  4.   

    最好关联一个ImageList控件
    这样通过图标更能直观。
    Tree1.SelectedNode.ImageIndex
      

  5.   


        public class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                //自已绘制
                this.treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
                this.treeView1.DrawNode+=new DrawTreeNodeEventHandler(treeView1_DrawNode);
            }        //在绘制节点事件中,按自已想的绘制
            private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
            {            if ((e.State & TreeNodeStates.Selected) != 0)
                {
                    //演示为绿底白字
                    e.Graphics.FillRectangle(Brushes.Green,e.Node.Bounds);                Font nodeFont = e.Node.NodeFont;
                    if (nodeFont == null) nodeFont = ((TreeView)sender).Font; 
                    e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White,
                        Rectangle.Inflate(e.Bounds, 2, 0));
                }
                else
                {
                    e.DrawDefault = true;
                }            if ((e.State & TreeNodeStates.Focused) != 0)
                {
                    using (Pen focusPen = new Pen(Color.Black))
                    {
                        focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                        Rectangle focusBounds = e.Node.Bounds ;
                        focusBounds.Size = new Size(focusBounds.Width - 1,
                        focusBounds.Height - 1);
                        e.Graphics.DrawRectangle(focusPen, focusBounds);
                    }
                }        }
        }
      

  6.   

    Tree1.SelectedNode.ForColor = Color.Black 
    然后在设置之前将其他的都改成默认不就可以了
      

  7.   

    给你个遮盖的方法把
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
            {
                TreeView _TreeView = (TreeView)sender;
                Control _SetLabel = _TreeView.Controls["SelectLab"];
                if (_SetLabel == null)
                {
                    Label _Label = new Label();
                    _Label.Name = "SelectLab";
                    _Label.AutoSize = false;
                    _Label.BackColor = Color.Yellow;
                    _Label.ForeColor = Color.Red;
                    _Label.Font = _TreeView.Font;
                    _TreeView.Controls.Add(_Label);
                    _SetLabel = _Label;
                }
                _SetLabel.Size = new Size(e.Node.Bounds.Width + 5, e.Node.Bounds.Height);
                _SetLabel.Location = new Point(e.Node.Bounds.X, e.Node.Bounds.Y);
                _SetLabel.Text = e.Node.Text;
            }
      

  8.   

    谢谢8楼,,,大家应该去试试哈,,ForColor对选中节点字体颜色是不起作用的,,,结帐,,,
      

  9.   

    tree1.TreeNodeStyle.Forecolor = color ;