fork download
  1. private void AssociateToolStripItems()
  2. {
  3. var menuitems = new Dictionary<string, ToolStripItem>();
  4. {
  5. Action<ToolStripItemCollection> subfunc = null;
  6. subfunc = (items) =>
  7. {
  8. foreach (ToolStripItem item in items)
  9. {
  10. if (item.Name.StartsWith("mi"))
  11. menuitems[item.Name.Substring(2)] = item;
  12.  
  13. if (item is ToolStripDropDownItem)
  14. subfunc((item as ToolStripDropDownItem).DropDownItems);
  15. }
  16. };
  17.  
  18. subfunc(menuStrip.Items);
  19. }
  20.  
  21. foreach (ToolStripItem item in toolStrip.Items)
  22. {
  23. if (item.Name.StartsWith("btn"))
  24. {
  25. var name = item.Name.Substring(3);
  26. if (!menuitems.ContainsKey(name))
  27. continue;
  28.  
  29. var mi = menuitems[name] as ToolStripMenuItem;
  30. if (mi == null)
  31. continue;
  32.  
  33. var btn = item as ToolStripButton;
  34. if (btn == null)
  35. continue;
  36.  
  37. mi.EnabledChanged += (s, e) => { btn.Enabled = mi.Enabled; };
  38. mi.CheckStateChanged += (s, e) => { btn.CheckState = mi.CheckState; };
  39. }
  40. }
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,22): error CS0116: A namespace can only contain types and namespace declarations
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty