/// <summary> /// Resize the width of the form if needed /// </summary> /// <param name="control"></param> private void ResizeIfNeeded(OptionsBaseControl control) { int controlWidth = control.Width; int controlHeight = control.Height; int panelWidth = m_mainPanel.Width; int panelHeight = m_mainPanel.Height; int formWidth = this.Width; int formHeight = this.Height; int diffWidth = formWidth - panelWidth; int diffHeight = formHeight - panelHeight; if (controlWidth > panelWidth) { this.Width = controlWidth + diffWidth; m_mainPanel.Width = controlWidth; } if (controlHeight > panelHeight) { this.Height = controlHeight + diffHeight; m_mainPanel.Height = controlHeight; } }
/// <summary> /// Resize the width of the form if needed /// </summary> /// <param name="control"></param> private void ResizeIfNeeded(OptionsBaseControl control) { int controlWidth = control.Width; int controlHeight = control.Height; int panelWidth = m_mainPanel.Width; int panelHeight = m_mainPanel.Height; int formWidth = this.Width; int formHeight = this.Height; int diffHeight = formHeight - panelHeight; if (controlWidth > panelWidth) { //Control width size is bigger than panel width size //Adjust size of form width to fit control width this.Width = controlWidth + (formWidth - panelWidth); } else if (controlWidth < panelWidth) { } if (controlHeight > panelHeight) { this.Height = controlHeight + diffHeight; m_mainPanel.Height = controlHeight; } }
private void SelectConfig(object sender, System.Windows.Forms.TreeViewEventArgs e) { if (e.Node is ConfigTreeNode) { //removes any controls if (m_mainPanel.Controls.Count > 0) { m_mainPanel.Controls.RemoveAt(0); } OptionsBaseControl control = ((ConfigTreeNode)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(((ConfigTreeNode)e.Node).GetConfigurationName()); } }
/// <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 ConfigTreeNode) { OptionsBaseControl configurationBaseControl = ((ConfigTreeNode)node).GetConfigurationControl(); //if (action == Action.Apply) configurationBaseControl.Apply(); //else if (action == Action.Restore) configurationBaseControl.Restore(); this.TreeWalker(node.Nodes, action); } } }
/// <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 ConfigTreeNode) { OptionsBaseControl control = ((ConfigTreeNode)node).GetConfigurationControl(); if (m_mainPanel.Controls.Contains((control))) { m_mainPanel.Controls.RemoveAt(0); } } break; } this.RemoveItem(node.Nodes, name); } }