This is the example code to get the hierarchical data with all Form names and embedded control names in "Text" property of TreeViewItem. You just need to call call "GetAllControl" function to iterate on forms.
void AddControl(TreeNodeCollection collection, Control ctrl)
{
TreeNode node = new TreeNode(ctrl.Name);
foreach (Control c in ctrl.Controls)
AddControl(node.Nodes, c);
collection.Add(node);
}
private TreeNodeCollection GetAllControls()
{
TreeNode rootNode = new TreeNode();
foreach (Form form in Application.OpenForms)
AddControl(rootNode.Nodes, form);
return rootNode.Nodes;
}
Usage Example:
private void Form1_Load(object sender, EventArgs e)
{
foreach (TreeNode node in GetAllControls())
treeView1.Nodes.Add(node);
}
P.S. I saw that I copied wring code in my previous answer, I tried to improve it but it is not updating. I don't know why is that, so I am posting another answer. Sorry for mess.