1: using System.Drawing;
2: using System.Windows.Forms;
3:
4: namespace RecipeBox.Tests.GUI_Tests
5: {
6: public class Spy : Form
7: {
8: readonly SplitContainer _splitContainer = new SplitContainer {Dock = DockStyle.Fill};
9: readonly TreeView _controlTree = new TreeView {Dock = DockStyle.Fill};
10: readonly PropertyGrid _properties = new PropertyGrid {Dock = DockStyle.Fill};
11:
12: public Spy()
13: {
14: Size = new Size(640, 480);
15: _splitContainer.Panel1.Controls.Add(_controlTree);
16: _splitContainer.Panel2.Controls.Add(_properties);
17: Controls.Add(_splitContainer);
18: _controlTree.NodeMouseClick += (sender, e) => _properties.SelectedObject = e.Node.Tag;
19: }
20:
21: public Spy(Control rootControl) : this()
22: {
23: _controlTree.Nodes.Add(GetTreeNode(rootControl));
24: }
25:
26: private static TreeNode GetTreeNode(Control control)
27: {
28: var node = new TreeNode(control + " (" + control.Name + ")") {Tag = control};
29: foreach (Control childControl in control.Controls)
30: node.Nodes.Add(GetTreeNode(childControl));
31: return node;
32: }
33: }
34: }