遍历 ToolStripMenuItem
时间: 2023-10-19 21:32:13 浏览: 142
遍历menu数据并显示
遍历ToolStripMenuItem的代码可以参考以下示例代码:
ToolStripMenuItem tool = (ToolStripMenuItem)sender;
for (int i = 0; i < this.初始状态ToolStripMenuItem.DropDownItems.Count; i++)
{
ToolStripMenuItem cb = this.初始状态ToolStripMenuItem.DropDownItems[i] as ToolStripMenuItem;
if (tool.Name.Equals(cb.Name))
{
cb.Enabled = false;
INIConfig.Writeini("工具", "初始状态", cb.Name, SuperVariable.ConfigPath);
开启ToolStripMenuItem.Enabled = true;
关闭ToolStripMenuItem.Enabled = false;
LogForm.GetInstance().SetLog("下次启动程序将" + cb.Name + "模式", Color.Lime);
MessageBoxEx.Show("下次启动程序将" + cb.Name + "模式");
}
else
{
cb.Enabled = true;
}
}
这段代码是通过循环遍历this.初始状态ToolStripMenuItem.DropDownItems中的所有ToolStripMenuItem,并根据条件进行相应的操作。
需要注意的是,这里的代码没有涉及对菜单的判断,即假设所有菜单列表中只有ToolStripMenuItem,而没有ToolStripSeparator。如果菜单中有ToolStripSeparator,需要添加一些条件判断的语句来处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [C# 遍历ToolStripMenuItem](https://blog.csdn.net/weixin_44713908/article/details/109489780)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [C# 控件基础1 | 从多态角度理解、遍历菜单栏控件ToolSplit](https://blog.csdn.net/a1062484747/article/details/130017050)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [C# 遍历菜单(menustrip)加入Treeview下](https://download.csdn.net/download/giser12/7849637)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文