/// <summary> /// 动态绑定TreeView,这里只限XML树为三级。 /// </summary> private void BindTree(Crownwood.DotNetMagic.Controls.TreeControl treeControl, XmlDocument _xmldoc) { XmlNodeList _list = _xmldoc.DocumentElement.ChildNodes; foreach (XmlElement elem in _list) { string strText = elem.Attributes["name"].Value; Crownwood.DotNetMagic.Controls.Node treeNode = new Crownwood.DotNetMagic.Controls.Node(strText); XmlNodeList clist = elem.ChildNodes; if (clist.Count > 0) { foreach (XmlElement celem in clist) { if (celem.ChildNodes.Count > 0) { string cText = celem.Attributes["name"].Value; Crownwood.DotNetMagic.Controls.Node ctreeNode = new Crownwood.DotNetMagic.Controls.Node(cText); ctreeNode.Tag = null; treeNode.Nodes.Add(ctreeNode); foreach (XmlElement elem3 in celem.ChildNodes) { string ctext3 = elem3.Attributes["name"].Value; string url = elem3.Attributes["url"].Value; if (Com.UserInfo.htRights.ContainsKey(url) || Com.UserInfo.eIBase == "1") { Crownwood.DotNetMagic.Controls.Node ctreeNode3 = new Crownwood.DotNetMagic.Controls.Node(ctext3); ctreeNode3.Tag = elem3.Attributes["url"].Value + "&" + elem3.Attributes["class"].Value + (elem3.Attributes.Count > 3 ? ("&" + elem3.Attributes["baseForm"].Value) : ""); ctreeNode.Nodes.Add(ctreeNode3); } } } else { string cText = celem.Attributes["name"].Value; string url = celem.Attributes["url"].Value; if (Com.UserInfo.htRights.ContainsKey(url) || Com.UserInfo.eIBase == "1") { Crownwood.DotNetMagic.Controls.Node ctreeNode = new Crownwood.DotNetMagic.Controls.Node(cText); ctreeNode.Tag = celem.Attributes["url"].Value + "&" + celem.Attributes["class"].Value + (celem.Attributes.Count > 3 ? ("&" + celem.Attributes["baseForm"].Value) : ""); treeNode.Nodes.Add(ctreeNode); } } } } if (treeNode.Nodes.Count > 0) { treeControl.Nodes.Add(treeNode); } } }
/// <summary> /// 动态绑定TreeView,这里只限XML树为三级。 /// </summary> private void BindTree(Crownwood.DotNetMagic.Controls.TreeControl treeControl, XmlDocument _xmldoc) { XmlNodeList _list = _xmldoc.DocumentElement.ChildNodes; foreach (XmlElement elem in _list) { string strText = elem.Attributes["name"].Value; Crownwood.DotNetMagic.Controls.Node treeNode = new Crownwood.DotNetMagic.Controls.Node(strText); treeControl.Nodes.Add(treeNode); XmlNodeList clist = elem.ChildNodes; if (clist.Count > 0) { foreach (XmlElement celem in clist) { if (celem.ChildNodes.Count > 0) { string cText = celem.Attributes["name"].Value; Crownwood.DotNetMagic.Controls.Node ctreeNode = new Crownwood.DotNetMagic.Controls.Node(cText); ctreeNode.Tag = null; treeNode.Nodes.Add(ctreeNode); foreach (XmlElement elem3 in celem.ChildNodes) { string ctext3 = elem3.Attributes["name"].Value; Crownwood.DotNetMagic.Controls.Node ctreeNode3 = new Crownwood.DotNetMagic.Controls.Node(ctext3); ctreeNode3.Tag = elem3.Attributes["url"].Value + "&" + elem3.Attributes["class"].Value; ctreeNode.Nodes.Add(ctreeNode3); } } else { string cText = celem.Attributes["name"].Value; Crownwood.DotNetMagic.Controls.Node ctreeNode = new Crownwood.DotNetMagic.Controls.Node(cText); ctreeNode.Tag = celem.Attributes["url"].Value + "&" + celem.Attributes["class"].Value; treeNode.Nodes.Add(ctreeNode); } } } } }
private void treeControl1_AfterSelect(Crownwood.DotNetMagic.Controls.TreeControl tc, Crownwood.DotNetMagic.Controls.NodeEventArgs e) { // Update the properties control with the newly selected control propertyGrid1.SelectedObject = treeControl1.SelectedNode.Tag; UpdateButtonState(); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.treeControl1 = new Crownwood.DotNetMagic.Controls.TreeControl(); this.contextMenu = new System.Windows.Forms.ContextMenu(); this.insertNode = new System.Windows.Forms.MenuItem(); this.appendNode = new System.Windows.Forms.MenuItem(); this.sep1 = new System.Windows.Forms.MenuItem(); this.addChild = new System.Windows.Forms.MenuItem(); this.sep2 = new System.Windows.Forms.MenuItem(); this.moveUp = new System.Windows.Forms.MenuItem(); this.moveDown = new System.Windows.Forms.MenuItem(); this.sep3 = new System.Windows.Forms.MenuItem(); this.removeNode = new System.Windows.Forms.MenuItem(); this.sep4 = new System.Windows.Forms.MenuItem(); this.clearAllNodes = new System.Windows.Forms.MenuItem(); this.labelCollection = new System.Windows.Forms.Label(); this.buttonOK = new System.Windows.Forms.Button(); this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); this.labelProperties = new System.Windows.Forms.Label(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonInsert = new System.Windows.Forms.Button(); this.buttonAppend = new System.Windows.Forms.Button(); this.buttonAddChild = new System.Windows.Forms.Button(); this.buttonRemove = new System.Windows.Forms.Button(); this.buttonClearAll = new System.Windows.Forms.Button(); this.buttonMoveDown = new System.Windows.Forms.Button(); this.buttonMoveUp = new System.Windows.Forms.Button(); this.SuspendLayout(); // // treeControl1 // this.treeControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.treeControl1.BorderColor = System.Drawing.SystemColors.ControlDark; this.treeControl1.BorderStyle = Crownwood.DotNetMagic.Controls.TreeBorderStyle.Solid; this.treeControl1.BoxDrawStyle = Crownwood.DotNetMagic.Controls.DrawStyle.Plain; this.treeControl1.CheckDrawStyle = Crownwood.DotNetMagic.Controls.DrawStyle.Plain; this.treeControl1.ContextMenuNode = this.contextMenu; this.treeControl1.ContextMenuSpace = this.contextMenu; this.treeControl1.GroupFont = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World); this.treeControl1.HotBackColor = System.Drawing.Color.Empty; this.treeControl1.HotForeColor = System.Drawing.Color.Empty; this.treeControl1.Location = new System.Drawing.Point(104, 32); this.treeControl1.Name = "treeControl1"; this.treeControl1.SelectedNode = null; this.treeControl1.SelectedNoFocusBackColor = System.Drawing.SystemColors.Control; this.treeControl1.SelectMode = Crownwood.DotNetMagic.Controls.SelectMode.Single; this.treeControl1.Size = new System.Drawing.Size(204, 380); this.treeControl1.TabIndex = 0; this.treeControl1.Text = "treeControl1"; this.treeControl1.AfterSelect += new Crownwood.DotNetMagic.Controls.NodeEventHandler(this.treeControl1_AfterSelect); // // contextMenu // this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.insertNode, this.appendNode, this.sep1, this.addChild, this.sep2, this.moveUp, this.moveDown, this.sep3, this.removeNode, this.sep4, this.clearAllNodes }); this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup); // // insertNode // this.insertNode.Index = 0; this.insertNode.Text = "Insert"; this.insertNode.Click += new System.EventHandler(this.insertNode_Click); // // appendNode // this.appendNode.Index = 1; this.appendNode.Text = "Append"; this.appendNode.Click += new System.EventHandler(this.appendNode_Click); // // sep1 // this.sep1.Index = 2; this.sep1.Text = "-"; // // addChild // this.addChild.Index = 3; this.addChild.Text = "Add Child"; this.addChild.Click += new System.EventHandler(this.addChild_Click); // // sep2 // this.sep2.Index = 4; this.sep2.Text = "-"; // // moveUp // this.moveUp.Index = 5; this.moveUp.Text = "Move Up"; this.moveUp.Click += new System.EventHandler(this.moveUp_Click); // // moveDown // this.moveDown.Index = 6; this.moveDown.Text = "Move Down"; this.moveDown.Click += new System.EventHandler(this.moveDown_Click); // // sep3 // this.sep3.Index = 7; this.sep3.Text = "-"; // // removeNode // this.removeNode.Index = 8; this.removeNode.Text = "Remove"; this.removeNode.Click += new System.EventHandler(this.removeNode_Click); // // sep4 // this.sep4.Index = 9; this.sep4.Text = "-"; // // clearAllNodes // this.clearAllNodes.Index = 10; this.clearAllNodes.Text = "Clear All"; this.clearAllNodes.Click += new System.EventHandler(this.clearAllNodes_Click); // // labelCollection // this.labelCollection.FlatStyle = System.Windows.Forms.FlatStyle.System; this.labelCollection.Location = new System.Drawing.Point(104, 8); this.labelCollection.Name = "labelCollection"; this.labelCollection.Size = new System.Drawing.Size(96, 23); this.labelCollection.TabIndex = 1; this.labelCollection.Text = "Menu Collection"; this.labelCollection.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // buttonOK // this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonOK.Location = new System.Drawing.Point(484, 428); this.buttonOK.Name = "buttonOK"; this.buttonOK.TabIndex = 3; this.buttonOK.Text = "OK"; this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); // // propertyGrid1 // this.propertyGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.propertyGrid1.CommandsVisibleIfAvailable = true; this.propertyGrid1.HelpVisible = false; this.propertyGrid1.LargeButtons = false; this.propertyGrid1.LineColor = System.Drawing.SystemColors.ControlDark; this.propertyGrid1.Location = new System.Drawing.Point(324, 32); this.propertyGrid1.Name = "propertyGrid1"; this.propertyGrid1.PropertySort = System.Windows.Forms.PropertySort.Alphabetical; this.propertyGrid1.Size = new System.Drawing.Size(232, 380); this.propertyGrid1.TabIndex = 1; this.propertyGrid1.Text = "propertyGrid1"; this.propertyGrid1.ToolbarVisible = false; this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window; this.propertyGrid1.ViewForeColor = System.Drawing.SystemColors.WindowText; // // labelProperties // this.labelProperties.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.labelProperties.FlatStyle = System.Windows.Forms.FlatStyle.System; this.labelProperties.Location = new System.Drawing.Point(328, 8); this.labelProperties.Name = "labelProperties"; this.labelProperties.TabIndex = 5; this.labelProperties.Text = "Menu Properties"; this.labelProperties.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // buttonCancel // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonCancel.Location = new System.Drawing.Point(396, 428); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.TabIndex = 2; this.buttonCancel.Text = "Cancel"; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // // buttonInsert // this.buttonInsert.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonInsert.Location = new System.Drawing.Point(16, 32); this.buttonInsert.Name = "buttonInsert"; this.buttonInsert.TabIndex = 6; this.buttonInsert.Text = "Insert"; this.buttonInsert.Click += new System.EventHandler(this.buttonInsert_Click); // // buttonAppend // this.buttonAppend.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonAppend.Location = new System.Drawing.Point(16, 64); this.buttonAppend.Name = "buttonAppend"; this.buttonAppend.TabIndex = 7; this.buttonAppend.Text = "Append"; this.buttonAppend.Click += new System.EventHandler(this.buttonAppend_Click); // // buttonAddChild // this.buttonAddChild.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonAddChild.Location = new System.Drawing.Point(16, 96); this.buttonAddChild.Name = "buttonAddChild"; this.buttonAddChild.TabIndex = 8; this.buttonAddChild.Text = "Add Child"; this.buttonAddChild.Click += new System.EventHandler(this.buttonAddChild_Click); // // buttonRemove // this.buttonRemove.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonRemove.Location = new System.Drawing.Point(16, 216); this.buttonRemove.Name = "buttonRemove"; this.buttonRemove.TabIndex = 9; this.buttonRemove.Text = "Remove"; this.buttonRemove.Click += new System.EventHandler(this.buttonRemove_Click); // // buttonClearAll // this.buttonClearAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonClearAll.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonClearAll.Location = new System.Drawing.Point(16, 388); this.buttonClearAll.Name = "buttonClearAll"; this.buttonClearAll.TabIndex = 10; this.buttonClearAll.Text = "Clear All"; this.buttonClearAll.Click += new System.EventHandler(this.buttonClearAll_Click); // // buttonMoveDown // this.buttonMoveDown.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonMoveDown.Location = new System.Drawing.Point(16, 168); this.buttonMoveDown.Name = "buttonMoveDown"; this.buttonMoveDown.Size = new System.Drawing.Size(72, 23); this.buttonMoveDown.TabIndex = 16; this.buttonMoveDown.Text = "Move Down"; this.buttonMoveDown.Click += new System.EventHandler(this.buttonMoveDown_Click); // // buttonMoveUp // this.buttonMoveUp.FlatStyle = System.Windows.Forms.FlatStyle.System; this.buttonMoveUp.Location = new System.Drawing.Point(16, 136); this.buttonMoveUp.Name = "buttonMoveUp"; this.buttonMoveUp.Size = new System.Drawing.Size(72, 23); this.buttonMoveUp.TabIndex = 15; this.buttonMoveUp.Text = "Move Up"; this.buttonMoveUp.Click += new System.EventHandler(this.buttonMoveUp_Click); // // MenuCollectionDialog // this.ClientSize = new System.Drawing.Size(572, 466); this.ControlBox = false; this.Controls.Add(this.buttonMoveDown); this.Controls.Add(this.buttonMoveUp); this.Controls.Add(this.buttonClearAll); this.Controls.Add(this.buttonRemove); this.Controls.Add(this.buttonAddChild); this.Controls.Add(this.buttonAppend); this.Controls.Add(this.buttonInsert); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.labelProperties); this.Controls.Add(this.propertyGrid1); this.Controls.Add(this.buttonOK); this.Controls.Add(this.labelCollection); this.Controls.Add(this.treeControl1); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.MaximizeBox = false; this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(472, 296); this.Name = "MenuCollectionDialog"; this.ShowInTaskbar = false; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Menu Collection Editor"; this.ResumeLayout(false); }