[英]Loop Through Menu Items in MDI Parent Form in WinForms
只要用戶執行啟動循環的操作,只需將ToolStipMenuItems
收集到一個List
並在列表上循環即可。
// First create the list of menu items
int selectedMenuItem = 0;
List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
menuItems.Add(systemManagementToolStripMenuItem);
// When the user performs some action, such as pressing down arrow
selectedMenuItem = (selectedMenuItem + 1) % menuItems.Count;
UpdateSelectedItems();
// Have some method to update the buttons
public void UpdateSelectedItems()
{
foreach(var item in menuItems)
item.BackColor = Color.DarkGray;
menuItems[selectedMenuItem].BackColor = Color.Gray;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.