SetMenuForm.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.IO;
  5. using System.Windows.Forms;
  6. using Autodesk.Revit.DB;
  7. using SAGY.DotNetUtils;
  8. using SAGY.DotNetUtils.Configration;
  9. using SAGY.DotNetUtils.WinForms;
  10. using TSZ.RevitMenu.Configuration;
  11. using ComboBox = Autodesk.Revit.UI.ComboBox;
  12. using Tab = TSZ.RevitMenu.Configuration.Tab;
  13. namespace SAGY.RevitMenu
  14. {
  15. public class SetMenuForm : BaseForm
  16. {
  17. private System.Windows.Forms.Button bn_Up;
  18. private System.Windows.Forms.Button btn_Add;
  19. private System.Windows.Forms.Button btn_Cancle;
  20. private System.Windows.Forms.Button btn_Delete;
  21. private System.Windows.Forms.Button btn_Down;
  22. private System.Windows.Forms.Button btn_OK;
  23. private System.Windows.Forms.Button btn_ReSet;
  24. private ComboBox comboBox1;
  25. private ComboBox comboBox2;
  26. private IContainer components;
  27. private GroupBox groupBox1;
  28. private GroupBox groupBox2;
  29. private Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> newDic = new Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>>();
  30. private Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> originDic = new Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>>();
  31. private TreeView treeView1;
  32. private TreeView treeView2;
  33. private List<string> xmlFile = new List<string>();
  34. public SetMenuForm()
  35. {
  36. this.InitializeComponent();
  37. }
  38. private void bn_Up_Click(object sender, EventArgs e)
  39. {
  40. if ((this.treeView2.SelectedNode != null) && (this.treeView2.SelectedNode.Parent != null))
  41. {
  42. if (this.treeView2.SelectedNode.Index > 0)
  43. {
  44. TreeNode selectedNode = this.treeView2.SelectedNode;
  45. int index = this.treeView2.SelectedNode.Index;
  46. this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(index--);
  47. this.treeView2.SelectedNode.Parent.Nodes.Insert(index, selectedNode);
  48. }
  49. else if (this.treeView2.SelectedNode.Parent.Index > 0)
  50. {
  51. TreeNode node = this.treeView2.SelectedNode;
  52. int num2 = this.treeView2.SelectedNode.Index;
  53. int num3 = this.treeView2.SelectedNode.Parent.Index;
  54. this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(num2);
  55. this.treeView2.Nodes[num3 - 1].Nodes.Add(node);
  56. }
  57. this.ChangeData();
  58. }
  59. }
  60. private void btn_Add_Click(object sender, EventArgs e)
  61. {
  62. Dictionary<TreeNode, TreeNode> dictionary = new Dictionary<TreeNode, TreeNode>();
  63. foreach (TreeNode node in this.treeView1.Nodes)
  64. {
  65. if ((node.Nodes != null) || (node.Nodes.Count > 0))
  66. {
  67. foreach (TreeNode node2 in node.Nodes)
  68. {
  69. if (node2.Checked)
  70. {
  71. dictionary.Add(node2, node2.Parent);
  72. }
  73. }
  74. }
  75. }
  76. List<string> list = new List<string>();
  77. List<TreeNode> list2 = new List<TreeNode>();
  78. foreach (KeyValuePair<TreeNode, TreeNode> pair in dictionary)
  79. {
  80. if (!list.Contains(pair.Value.Text))
  81. {
  82. list.Add(pair.Value.Text);
  83. TreeNode item = new TreeNode(pair.Value.Text) {
  84. Tag = pair.Value.Tag
  85. };
  86. list2.Add(item);
  87. }
  88. }
  89. int num = 0;
  90. foreach (string str in list)
  91. {
  92. bool flag = false;
  93. foreach (TreeNode node4 in this.treeView2.Nodes)
  94. {
  95. if (str == node4.Text)
  96. {
  97. flag = true;
  98. break;
  99. }
  100. }
  101. if (!flag)
  102. {
  103. new TreeNode(str);
  104. this.treeView2.Nodes.Add(list2[num]);
  105. }
  106. num++;
  107. }
  108. foreach (KeyValuePair<TreeNode, TreeNode> pair2 in dictionary)
  109. {
  110. foreach (TreeNode node5 in this.treeView2.Nodes)
  111. {
  112. if (((node5.Nodes == null) && (node5.Nodes.Count <= 0)) || !(node5.Text == pair2.Value.Text))
  113. {
  114. continue;
  115. }
  116. bool flag2 = false;
  117. foreach (TreeNode node6 in node5.Nodes)
  118. {
  119. if (node6.Text == pair2.Key.Text)
  120. {
  121. flag2 = true;
  122. break;
  123. }
  124. }
  125. if (!flag2)
  126. {
  127. node5.Nodes.Add(pair2.Key.Clone() as TreeNode);
  128. }
  129. }
  130. }
  131. this.ChangeData();
  132. }
  133. private void btn_Cancle_Click(object sender, EventArgs e)
  134. {
  135. base.Close();
  136. base.DialogResult = DialogResult.Cancel;
  137. }
  138. private void btn_Delete_Click(object sender, EventArgs e)
  139. {
  140. for (int i = 0; i < this.treeView2.Nodes.Count; i++)
  141. {
  142. TreeNode node = this.treeView2.Nodes[i];
  143. if (node.Checked)
  144. {
  145. node.Remove();
  146. i--;
  147. }
  148. else
  149. {
  150. for (int j = 0; j < node.Nodes.Count; j++)
  151. {
  152. if (node.Nodes[j].Checked)
  153. {
  154. node.Nodes[j].Remove();
  155. j--;
  156. }
  157. }
  158. }
  159. }
  160. this.ChangeData();
  161. }
  162. private void btn_Down_Click(object sender, EventArgs e)
  163. {
  164. if ((this.treeView2.SelectedNode != null) && (this.treeView2.SelectedNode.Parent != null))
  165. {
  166. if (this.treeView2.SelectedNode.Index < (this.treeView2.SelectedNode.Parent.Nodes.Count - 1))
  167. {
  168. TreeNode selectedNode = this.treeView2.SelectedNode;
  169. int index = this.treeView2.SelectedNode.Index;
  170. this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(index++);
  171. this.treeView2.SelectedNode.Parent.Nodes.Insert(index, selectedNode);
  172. }
  173. else if (this.treeView2.SelectedNode.Parent.Index < (this.treeView2.Nodes.Count - 1))
  174. {
  175. TreeNode node = this.treeView2.SelectedNode;
  176. int num2 = this.treeView2.SelectedNode.Index;
  177. int num3 = this.treeView2.SelectedNode.Parent.Index;
  178. this.treeView2.SelectedNode.Parent.Nodes.RemoveAt(num2);
  179. this.treeView2.Nodes[num3 + 1].Nodes.Insert(0, node);
  180. }
  181. this.ChangeData();
  182. }
  183. }
  184. private void btn_OK_Click(object sender, EventArgs e)
  185. {
  186. List<Menus> list = new List<Menus>();
  187. string strPath = Path.Combine(AppBaseInfo.AppRunPath, "Menu");
  188. string path = Path.Combine(Path.Combine(AppBaseInfo.AppTempFilePath, "Menu"), AppBaseInfo.LoadArgs);
  189. this.ReadXML(this.xmlFile, list, strPath);
  190. foreach (Menus menus in list)
  191. {
  192. string appName = menus.App.AppName;
  193. List<Tab> list2 = new List<Tab>();
  194. List<TSZ.RevitMenu.Configuration.Panel> list3 = new List<TSZ.RevitMenu.Configuration.Panel>();
  195. foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in this.newDic)
  196. {
  197. if (pair.Key.Modules == appName)
  198. {
  199. list2.Add(pair.Key);
  200. list3.AddRange(pair.Value);
  201. }
  202. }
  203. if (list2.Count > 0)
  204. {
  205. menus.Tab = list2.ToArray();
  206. }
  207. if (list3.Count > 0)
  208. {
  209. menus.Panel = list3.ToArray();
  210. }
  211. if (!Directory.Exists(path))
  212. {
  213. Directory.CreateDirectory(path);
  214. }
  215. XMLFile.SaveXMLFile<Menus>(Path.Combine(path, appName + ".xml"), menus);
  216. }
  217. base.DialogResult = DialogResult.OK;
  218. }
  219. private void btn_ReSet_Click(object sender, EventArgs e)
  220. {
  221. string path = Path.Combine(Path.Combine(AppBaseInfo.AppTempFilePath, "Menu"), AppBaseInfo.LoadArgs);
  222. if (Directory.Exists(path))
  223. {
  224. DirectoryInfo info = new DirectoryInfo(path);
  225. foreach (FileInfo info2 in info.GetFiles("*.xml"))
  226. {
  227. info2.Delete();
  228. }
  229. }
  230. base.DialogResult = DialogResult.OK;
  231. }
  232. private void ChangeData()
  233. {
  234. foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in this.newDic)
  235. {
  236. if (pair.Key.TabName == this.comboBox2.Text)
  237. {
  238. Tab key = pair.Key;
  239. this.newDic.Remove(pair.Key);
  240. List<TSZ.RevitMenu.Configuration.Panel> list = new List<TSZ.RevitMenu.Configuration.Panel>();
  241. foreach (TreeNode node in this.treeView2.Nodes)
  242. {
  243. TSZ.RevitMenu.Configuration.Panel tag = node.Tag as TSZ.RevitMenu.Configuration.Panel;
  244. TSZ.RevitMenu.Configuration.Button[] buttonArray = new TSZ.RevitMenu.Configuration.Button[node.Nodes.Count];
  245. for (int i = 0; i < node.Nodes.Count; i++)
  246. {
  247. buttonArray[i] = node.Nodes[i].Tag as TSZ.RevitMenu.Configuration.Button;
  248. buttonArray[i].MenuTab = pair.Key.MenuTab;
  249. buttonArray[i].Modules = pair.Key.Modules;
  250. }
  251. tag.Button = buttonArray;
  252. list.Add(tag);
  253. }
  254. this.newDic.Add(key, list);
  255. break;
  256. }
  257. }
  258. }
  259. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  260. {
  261. this.LoadTreeView(this.comboBox1, this.comboBox1.Text, this.treeView1, this.originDic);
  262. }
  263. private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  264. {
  265. this.LoadTreeView(this.comboBox2, this.comboBox2.Text, this.treeView2, this.newDic);
  266. }
  267. protected override void Dispose(bool disposing)
  268. {
  269. if (disposing && (this.components != null))
  270. {
  271. this.components.Dispose();
  272. }
  273. base.Dispose(disposing);
  274. }
  275. private void GetDictionary(List<Menus> menus, Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> dic)
  276. {
  277. List<Tab> list = new List<Tab>();
  278. List<TSZ.RevitMenu.Configuration.Panel> list2 = new List<TSZ.RevitMenu.Configuration.Panel>();
  279. for (int i = 0; i < menus.Count; i++)
  280. {
  281. list.AddRange(menus[i].Tab);
  282. list2.AddRange(menus[i].Panel);
  283. }
  284. foreach (Tab tab in list)
  285. {
  286. List<TSZ.RevitMenu.Configuration.Panel> list3 = new List<TSZ.RevitMenu.Configuration.Panel>();
  287. foreach (TSZ.RevitMenu.Configuration.Panel panel in list2)
  288. {
  289. if (((panel.Button.Length > 0) && (panel.Button[0].MenuTab == tab.MenuTab)) && (panel.Button[0].Modules == tab.Modules))
  290. {
  291. list3.Add(panel);
  292. }
  293. }
  294. dic.Add(tab, list3);
  295. }
  296. }
  297. private void InitializeComponent()
  298. {
  299. this.comboBox1 = new ComboBox();
  300. this.btn_Add = new System.Windows.Forms.Button();
  301. this.btn_Delete = new System.Windows.Forms.Button();
  302. this.bn_Up = new System.Windows.Forms.Button();
  303. this.btn_Down = new System.Windows.Forms.Button();
  304. this.btn_OK = new System.Windows.Forms.Button();
  305. this.btn_Cancle = new System.Windows.Forms.Button();
  306. this.treeView1 = new TreeView();
  307. this.treeView2 = new TreeView();
  308. this.groupBox1 = new GroupBox();
  309. this.groupBox2 = new GroupBox();
  310. this.comboBox2 = new ComboBox();
  311. this.btn_ReSet = new System.Windows.Forms.Button();
  312. this.groupBox1.SuspendLayout();
  313. this.groupBox2.SuspendLayout();
  314. base.SuspendLayout();
  315. this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
  316. this.comboBox1.FormattingEnabled = true;
  317. this.comboBox1.Location = new Point(6, 0x10);
  318. this.comboBox1.Name = "comboBox1";
  319. this.comboBox1.Size = new Size(0x9e, 20);
  320. this.comboBox1.TabIndex = 0;
  321. this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
  322. this.btn_Add.Location = new Point(370, 0x4a);
  323. this.btn_Add.Name = "btn_Add";
  324. this.btn_Add.Size = new Size(0x4b, 0x17);
  325. this.btn_Add.TabIndex = 4;
  326. this.btn_Add.Text = "添加";
  327. this.btn_Add.UseVisualStyleBackColor = true;
  328. this.btn_Add.Click += new EventHandler(this.btn_Add_Click);
  329. this.btn_Delete.Location = new Point(370, 0x71);
  330. this.btn_Delete.Name = "btn_Delete";
  331. this.btn_Delete.Size = new Size(0x4b, 0x17);
  332. this.btn_Delete.TabIndex = 5;
  333. this.btn_Delete.Text = "删除";
  334. this.btn_Delete.UseVisualStyleBackColor = true;
  335. this.btn_Delete.Click += new EventHandler(this.btn_Delete_Click);
  336. this.bn_Up.Location = new Point(370, 0x9c);
  337. this.bn_Up.Name = "bn_Up";
  338. this.bn_Up.Size = new Size(0x4b, 0x17);
  339. this.bn_Up.TabIndex = 6;
  340. this.bn_Up.Text = "上移";
  341. this.bn_Up.UseVisualStyleBackColor = true;
  342. this.bn_Up.Click += new EventHandler(this.bn_Up_Click);
  343. this.btn_Down.Location = new Point(370, 0xc7);
  344. this.btn_Down.Name = "btn_Down";
  345. this.btn_Down.Size = new Size(0x4b, 0x17);
  346. this.btn_Down.TabIndex = 7;
  347. this.btn_Down.Text = "下移";
  348. this.btn_Down.UseVisualStyleBackColor = true;
  349. this.btn_Down.Click += new EventHandler(this.btn_Down_Click);
  350. this.btn_OK.Location = new Point(0x114, 0x139);
  351. this.btn_OK.Name = "btn_OK";
  352. this.btn_OK.Size = new Size(0x4b, 0x17);
  353. this.btn_OK.TabIndex = 8;
  354. this.btn_OK.Text = "确定";
  355. this.btn_OK.UseVisualStyleBackColor = true;
  356. this.btn_OK.Click += new EventHandler(this.btn_OK_Click);
  357. this.btn_Cancle.Location = new Point(370, 0x139);
  358. this.btn_Cancle.Name = "btn_Cancle";
  359. this.btn_Cancle.Size = new Size(0x4b, 0x17);
  360. this.btn_Cancle.TabIndex = 9;
  361. this.btn_Cancle.Text = "取消";
  362. this.btn_Cancle.UseVisualStyleBackColor = true;
  363. this.btn_Cancle.Click += new EventHandler(this.btn_Cancle_Click);
  364. this.treeView1.CheckBoxes = true;
  365. this.treeView1.Location = new Point(6, 0x21);
  366. this.treeView1.Name = "treeView1";
  367. this.treeView1.Size = new Size(0x9e, 0xfd);
  368. this.treeView1.TabIndex = 10;
  369. this.treeView1.AfterCheck += new TreeViewEventHandler(this.treeView1_AfterCheck);
  370. this.treeView2.CheckBoxes = true;
  371. this.treeView2.Location = new Point(6, 0x21);
  372. this.treeView2.Name = "treeView2";
  373. this.treeView2.Size = new Size(0x9e, 0xfd);
  374. this.treeView2.TabIndex = 11;
  375. this.treeView2.AfterCheck += new TreeViewEventHandler(this.treeView2_AfterCheck);
  376. this.groupBox1.Controls.Add(this.treeView1);
  377. this.groupBox1.Controls.Add(this.comboBox1);
  378. this.groupBox1.Location = new Point(12, 0x10);
  379. this.groupBox1.Name = "groupBox1";
  380. this.groupBox1.Size = new Size(0xa9, 0x126);
  381. this.groupBox1.TabIndex = 14;
  382. this.groupBox1.TabStop = false;
  383. this.groupBox1.Text = "设置前菜单";
  384. this.groupBox2.Controls.Add(this.comboBox2);
  385. this.groupBox2.Controls.Add(this.treeView2);
  386. this.groupBox2.Location = new Point(0xbb, 0x10);
  387. this.groupBox2.Name = "groupBox2";
  388. this.groupBox2.Size = new Size(0xa9, 0x126);
  389. this.groupBox2.TabIndex = 15;
  390. this.groupBox2.TabStop = false;
  391. this.groupBox2.Text = "设置后菜单";
  392. this.comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
  393. this.comboBox2.FormattingEnabled = true;
  394. this.comboBox2.Location = new Point(6, 0x10);
  395. this.comboBox2.Name = "comboBox2";
  396. this.comboBox2.Size = new Size(0x9e, 20);
  397. this.comboBox2.TabIndex = 11;
  398. this.comboBox2.SelectedIndexChanged += new EventHandler(this.comboBox2_SelectedIndexChanged);
  399. this.btn_ReSet.Location = new Point(0xb0, 0x13c);
  400. this.btn_ReSet.Name = "btn_ReSet";
  401. this.btn_ReSet.Size = new Size(0x4b, 0x17);
  402. this.btn_ReSet.TabIndex = 0x10;
  403. this.btn_ReSet.Text = "恢复设置";
  404. this.btn_ReSet.UseVisualStyleBackColor = true;
  405. this.btn_ReSet.Click += new EventHandler(this.btn_ReSet_Click);
  406. base.AutoScaleDimensions = new SizeF(6f, 12f);
  407. base.AutoScaleMode = AutoScaleMode.Font;
  408. base.ClientSize = new Size(0x1c5, 350);
  409. base.Controls.Add(this.btn_ReSet);
  410. base.Controls.Add(this.groupBox2);
  411. base.Controls.Add(this.groupBox1);
  412. base.Controls.Add(this.btn_Cancle);
  413. base.Controls.Add(this.btn_OK);
  414. base.Controls.Add(this.btn_Down);
  415. base.Controls.Add(this.bn_Up);
  416. base.Controls.Add(this.btn_Delete);
  417. base.Controls.Add(this.btn_Add);
  418. base.MaximizeBox = false;
  419. base.MinimizeBox = false;
  420. base.Name = "SetMenuForm";
  421. this.Text = "设置菜单";
  422. base.Load += new EventHandler(this.SetMenuForm_Load);
  423. this.groupBox1.ResumeLayout(false);
  424. this.groupBox2.ResumeLayout(false);
  425. base.ResumeLayout(false);
  426. }
  427. private void LoadData(ComboBox cmb, Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> dic)
  428. {
  429. foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in dic)
  430. {
  431. cmb.Items.Add(pair.Key.TabName);
  432. }
  433. if (cmb.Items.Count > 0)
  434. {
  435. cmb.SelectedIndex = 0;
  436. }
  437. }
  438. private void LoadTreeView(ComboBox cmb, string tabName, TreeView tv, Dictionary<Tab, List<TSZ.RevitMenu.Configuration.Panel>> dic)
  439. {
  440. tv.Nodes.Clear();
  441. foreach (KeyValuePair<Tab, List<TSZ.RevitMenu.Configuration.Panel>> pair in dic)
  442. {
  443. if (pair.Key.TabName == tabName)
  444. {
  445. foreach (TSZ.RevitMenu.Configuration.Panel panel in pair.Value)
  446. {
  447. TreeNode node = new TreeNode(panel.PanelName) {
  448. Tag = panel
  449. };
  450. foreach (TSZ.RevitMenu.Configuration.Button button in panel.Button)
  451. {
  452. if (button.ButtonStyles == "Separator")
  453. {
  454. button.ButtonText = "——";
  455. }
  456. TreeNode node2 = new TreeNode(button.ButtonText) {
  457. Tag = button
  458. };
  459. node.Nodes.Add(node2);
  460. }
  461. tv.Nodes.Add(node);
  462. }
  463. }
  464. }
  465. }
  466. private void ReadXML(List<string> xmlFile, List<Menus> menus, string strPath)
  467. {
  468. DirectoryInfo info = new DirectoryInfo(strPath);
  469. foreach (FileInfo info2 in info.GetFiles("*.xml"))
  470. {
  471. Menus x = new Menus();
  472. if (xmlFile.Contains(Path.GetFileNameWithoutExtension(info2.FullName)))
  473. {
  474. XMLFile.OpenXMLFile<Menus>(info2.FullName, ref x);
  475. menus.Add(x);
  476. }
  477. }
  478. }
  479. private void SetMenuForm_Load(object sender, EventArgs e)
  480. {
  481. this.xmlFile.AddRange(AppBaseInfo.LoadArgs.ToString().Split(new char[] { ',' }));
  482. List<Menus> menus = new List<Menus>();
  483. List<Menus> list2 = new List<Menus>();
  484. string strPath = Path.Combine(AppBaseInfo.AppRunPath, "Menu");
  485. string path = Path.Combine(AppBaseInfo.AppTempFilePath, "Menu");
  486. this.ReadXML(this.xmlFile, menus, strPath);
  487. if (Directory.Exists(path))
  488. {
  489. this.ReadXML(this.xmlFile, list2, path);
  490. }
  491. this.GetDictionary(menus, this.originDic);
  492. if ((list2 != null) && (list2.Count > 0))
  493. {
  494. this.GetDictionary(list2, this.newDic);
  495. }
  496. else
  497. {
  498. this.newDic = this.originDic;
  499. }
  500. this.LoadData(this.comboBox1, this.originDic);
  501. this.LoadData(this.comboBox2, this.newDic);
  502. }
  503. private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
  504. {
  505. TreeViewChecked(e);
  506. }
  507. private void treeView2_AfterCheck(object sender, TreeViewEventArgs e)
  508. {
  509. TreeViewChecked(e);
  510. }
  511. private static void TreeViewChecked(TreeViewEventArgs e)
  512. {
  513. if (e.Action != TreeViewAction.Unknown)
  514. {
  515. if (e.Node.Parent == null)
  516. {
  517. foreach (TreeNode node in e.Node.Nodes)
  518. {
  519. node.Checked = e.Node.Checked;
  520. }
  521. }
  522. else if (!e.Node.Checked)
  523. {
  524. e.Node.Parent.Checked = e.Node.Checked;
  525. }
  526. }
  527. }
  528. }
  529. }