private void AssociateToolStripItems()
{
var menuitems = new Dictionary<string, ToolStripItem>();
{
Action<ToolStripItemCollection> subfunc = null;
subfunc = (items) =>
{
foreach (ToolStripItem item in items)
{
if (item.Name.StartsWith("mi"))
menuitems[item.Name.Substring(2)] = item;
if (item is ToolStripDropDownItem)
subfunc((item as ToolStripDropDownItem).DropDownItems);
}
};
subfunc(menuStrip.Items);
}
foreach (ToolStripItem item in toolStrip.Items)
{
if (item.Name.StartsWith("btn"))
{
var name = item.Name.Substring(3);
if (!menuitems.ContainsKey(name))
continue;
var mi = menuitems[name] as ToolStripMenuItem;
if (mi == null)
continue;
var btn = item as ToolStripButton;
if (btn == null)
continue;
mi.EnabledChanged += (s, e) => { btn.Enabled = mi.Enabled; };
mi.CheckStateChanged += (s, e) => { btn.CheckState = mi.CheckState; };
}
}
}
ICAgICAgICBwcml2YXRlIHZvaWQgQXNzb2NpYXRlVG9vbFN0cmlwSXRlbXMoKQogICAgICAgIHsKICAgICAgICAgICAgdmFyIG1lbnVpdGVtcyA9IG5ldyBEaWN0aW9uYXJ5PHN0cmluZywgVG9vbFN0cmlwSXRlbT4oKTsKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQWN0aW9uPFRvb2xTdHJpcEl0ZW1Db2xsZWN0aW9uPiBzdWJmdW5jID0gbnVsbDsKICAgICAgICAgICAgICAgIHN1YmZ1bmMgPSAoaXRlbXMpID0+CiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgZm9yZWFjaCAoVG9vbFN0cmlwSXRlbSBpdGVtIGluIGl0ZW1zKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGl0ZW0uTmFtZS5TdGFydHNXaXRoKCJtaSIpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgbWVudWl0ZW1zW2l0ZW0uTmFtZS5TdWJzdHJpbmcoMildID0gaXRlbTsKCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpdGVtIGlzIFRvb2xTdHJpcERyb3BEb3duSXRlbSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1YmZ1bmMoKGl0ZW0gYXMgVG9vbFN0cmlwRHJvcERvd25JdGVtKS5Ecm9wRG93bkl0ZW1zKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9OwoKICAgICAgICAgICAgICAgIHN1YmZ1bmMobWVudVN0cmlwLkl0ZW1zKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgZm9yZWFjaCAoVG9vbFN0cmlwSXRlbSBpdGVtIGluIHRvb2xTdHJpcC5JdGVtcykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKGl0ZW0uTmFtZS5TdGFydHNXaXRoKCJidG4iKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB2YXIgbmFtZSA9IGl0ZW0uTmFtZS5TdWJzdHJpbmcoMyk7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFtZW51aXRlbXMuQ29udGFpbnNLZXkobmFtZSkpCiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwoKICAgICAgICAgICAgICAgICAgICB2YXIgbWkgPSBtZW51aXRlbXNbbmFtZV0gYXMgVG9vbFN0cmlwTWVudUl0ZW07CiAgICAgICAgICAgICAgICAgICAgaWYgKG1pID09IG51bGwpCiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwoKICAgICAgICAgICAgICAgICAgICB2YXIgYnRuID0gaXRlbSBhcyBUb29sU3RyaXBCdXR0b247CiAgICAgICAgICAgICAgICAgICAgaWYgKGJ0biA9PSBudWxsKQogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKCiAgICAgICAgICAgICAgICAgICAgbWkuRW5hYmxlZENoYW5nZWQgKz0gKHMsIGUpID0+IHsgYnRuLkVuYWJsZWQgPSBtaS5FbmFibGVkOyB9OwogICAgICAgICAgICAgICAgICAgIG1pLkNoZWNrU3RhdGVDaGFuZ2VkICs9IChzLCBlKSA9PiB7IGJ0bi5DaGVja1N0YXRlID0gbWkuQ2hlY2tTdGF0ZTsgfTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0=
prog.cs(1,22): error CS0116: A namespace can only contain types and namespace declarations
Compilation failed: 1 error(s), 0 warnings