解决方案 »

  1.   

    解决了,思路是在节点后加一个标签控件,代码如下:        private void Form1_Load(object sender, EventArgs e)
            {            treeView1.AfterExpand += new TreeViewEventHandler(TV1_AfterExpand);
                treeView1.AfterCollapse += new TreeViewEventHandler(TV1_AfterCollapse);
                
                TreeNode tn1 = new TreeNode();
                tn1.Text = "aaa";
                tn1.Name = "aaa";
                treeView1.Nodes.Add(tn1);            TreeNode tn2 = new TreeNode();
                tn2.Text = "bbb";
                tn2.Name = "bbb";
                tn1.Nodes.Add(tn2);            Label lb2 = new Label();
                lb2.ForeColor = System.Drawing.Color.Blue;
                lb2.Text = " (3)";
                lb2.Parent = treeView1;
                tn2.Tag = lb2;
                lb2.Tag = tn2;
               
                TreeNode tn3 = new TreeNode();
                tn3.Text = "ccc";
                tn3.Name = "ccc";
                tn1.Nodes.Add(tn3);
                Label lb3 = new Label();
                lb3.ForeColor = System.Drawing.Color.Blue;
                lb3.Parent = treeView1;
                lb3.Text = " (0)";
                tn3.Tag = lb3;
                lb3.Tag = tn3;            treeView1.SelectedNode = tn2;            zSetLabel(treeView1.Nodes[0], true);
            }        void TV1_AfterCollapse(object sender, TreeViewEventArgs e)
            {
                zSetLabel(e.Node, false);
            }        void TV1_AfterExpand(object sender, TreeViewEventArgs e)
            {
                zSetLabel(e.Node, true);
            }        void zSetLabel(TreeNode ParentNode, bool Visible)
            {
                foreach (TreeNode ChildNode in ParentNode.Nodes)
                {
                    Label B = (Label)ChildNode.Tag;
                    B.Location = ChildNode.Bounds.Location;
                    B.Left += ChildNode.Bounds.Width;
                    B.Height = ChildNode.Bounds.Height;
                    B.Visible = Visible;
                }
            }
      

  2.   

    treeView DrawMode = DrawText//DrawNode事件,我是用 | 区分左右不分的,这个逻辑可以自己控制
                string[] strs = e.Node.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (strs.Length > 1 &&(e.Node.Parent == null || e.Node.Parent.IsExpanded))
                {
                    Font fontT = _treeCtrls.Font;
                    Font font = new Font(fontT.FontFamily, fontT.Size, FontStyle.Bold);
                    e.Graphics.DrawString(strs[0], font, Brushes.Black, e.Bounds.Location);
                    SizeF strSize = e.Graphics.MeasureString(strs[0], font);
                    e.Graphics.DrawString(strs[1], fontT, Brushes.Black, new PointF(e.Bounds.Left + strSize.Width + 3, e.Bounds.Top));
                }
                else
                {
                    e.DrawDefault = true;
                }