private void 递归遍历树节点(TreeNodeCollection aNodes)
{
foreach (TreeNode iNode in aNodes)
{
textBox1.Text = textBox1.Text +
Environment.NewLine + //换行,添加新行
"名称:" + iNode.Name + " | " +
"Caption:" + iNode.Text + " | " +
"Index:" + iNode.Index.ToString();
if (iNode.Nodes.Count > 0)
{
递归遍历树节点(iNode.Nodes);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int iLine;
iLine = treeView1.GetNodeCount(true);
textBox1.Text = "总结点数:" + iLine.ToString() +
Environment.NewLine + "现在开始遍历节点:";
递归遍历树节点(treeView1.Nodes);
}