private void tbnModuleAdd_Click(object sender, EventArgs e) { UiTreeNode node = tvUI.SelectedNode as UiTreeNode; if (node == null || !(node.ContextObject is GUISystemModule)) { MessageBox.Show("请选择结点"); return; } ModuleDlg dlg = new ModuleDlg(); dlg.Text = "添加模块信息"; if (dlg.ShowDialog() == DialogResult.OK) { GUISystemModule systemModule = node.ContextObject as GUISystemModule; if (systemModule == null) { return; } GUIModule module = new GUIModule(systemModule); module.Caption = dlg.txtCaption.Text.Trim(); module.Name = dlg.txtName.Text.Trim(); module.Description = dlg.txtDescription.Text.Trim(); systemModule.Modules.Add(module); UiTreeNode moduleNode = new UiTreeNode(module); node.Nodes.Add(moduleNode); } }
private void tbnModuleDelete_Click(object sender, EventArgs e) { UiTreeNode node = tvUI.SelectedNode as UiTreeNode; if (node == null || !(node.ContextObject is GUIModule)) { MessageBox.Show("请选择结点"); return; } GUIModule module = node.ContextObject as GUIModule; UiTreeNode systemModuleNode = node.Parent as UiTreeNode; GUISystemModule systemModule = systemModuleNode.ContextObject as GUISystemModule; if (systemModule == null || !(node.ContextObject is GUISystemModule)) { return; } systemModule.Modules.RemoveAll(o => o.Name == module.Name); systemModuleNode.Nodes.Remove(node); }