/// <summary> /// When the Restor or Apply command are initiated, visit each tree node, get its related control and call the method (Restore, Apply) /// </summary> /// <param name="treeCollection"></param> /// <param name="action"></param> private void TreeWalker(TreeNodeCollection treeCollection, Action action) { if (treeCollection == null) { return; } foreach (TreeNode node in treeCollection) { if (node is ConfigurationTreeNode) { ConfigurationBaseControl configurationBaseControl = ((ConfigurationTreeNode)node).GetConfigurationControl(); if (action == Action.Apply) { configurationBaseControl.Apply(); } else if (action == Action.Restore) { configurationBaseControl.Restore(); } this.TreeWalker(node.Nodes, action); } } }
/// <summary> /// Resize the width of the form if needed /// </summary> /// <param name="control"></param> private void ResizeIfNeeded(ConfigurationBaseControl control) { int controlWidth = control.Width; int panelWidth = m_mainPanel.Width; int appWidth = this.Width; int diff = appWidth - panelWidth; if (controlWidth > panelWidth) { this.Width = controlWidth + diff; m_mainPanel.Width = controlWidth; } }
private void SelectConfig(object sender, System.Windows.Forms.TreeViewEventArgs e) { if (e.Node is ConfigurationTreeNode) { //removes any controls if (m_mainPanel.Controls.Count > 0) { m_mainPanel.Controls.RemoveAt(0); } ConfigurationBaseControl control = ((ConfigurationTreeNode)e.Node).GetConfigurationControl(); //add the current control to the main panel this.ResizeIfNeeded(control); m_mainPanel.Controls.Add(control); //set the name of the control this.SetLabel(((ConfigurationTreeNode)e.Node).GetConfigurationName()); } }
/// <summary> /// Remove tree node item with specified name /// </summary> /// <param name="treeCollection"></param> /// <param name="name"></param> private void RemoveItem(TreeNodeCollection treeCollection, string name) { if (treeCollection == null) { return; } foreach (TreeNode node in treeCollection) { if (string.Equals(node.Text, name)) { m_optionsTV.Nodes.Remove(node); if (node is ConfigurationTreeNode) { ConfigurationBaseControl control = ((ConfigurationTreeNode)node).GetConfigurationControl(); if (m_mainPanel.Controls.Contains((control))) { m_mainPanel.Controls.RemoveAt(0); } } break; } this.RemoveItem(node.Nodes, name); } }
public ConfigurationTreeNode(string nodeName, ConfigurationBaseControl relatedControl) : base(nodeName) { m_userControl = relatedControl; m_userControl.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top; }