解决方案 »
- 怎样用Grid View读取txt文件?
- 如何让我创建的excel.application与双击打开的excel文件使用不同的进程
- 实现导出为 .txt格式(在线求解)
- IE的代理验证窗口[醒目,唯一的40分献给高手]
- 解析E2BA8465....
- 怎样设置默认的工具栏控件列表
- 在InitializeComponent() 的System.EventHandler 报未将对象引用设置到对象的实例 错误
- 如何解决关闭主窗体而不关闭整个程序的问题?(我是一个刚学习C#的莱鸟,大家不笑,帮帮忙吧)
- **————————**页面下载认证的问题?**——————---**
- 救命啊!
- 求助一段Delph代码转换C#爆内存的问题
- C# TreeView和反射的问题
{ 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;
}
}
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;
}