static public MenuItem CloneMenu(MenuItemEx currentItem) { MenuItemEx clonedItem = new MenuItemEx(currentItem.Text, (Bitmap)currentItem.Icon, (Shortcut)currentItem.Shortcut, currentItem.ClickHandler); // Preserve the enable and check state clonedItem.Enabled = currentItem.Enabled; clonedItem.Checked = currentItem.Checked; clonedItem.RadioCheck = currentItem.RadioCheck; foreach (MenuItemEx item in currentItem.MenuItems) { clonedItem.MenuItems.Add(CloneMenu(item)); } return(clonedItem); }
void CreateContextMenu() { // context menu MenuItemEx largeIconsMenu = new MenuItemEx("Large Icons", new EventHandler(OnContextMenu)); MenuItemEx smallIconsMenu = new MenuItemEx("Small Icons", new EventHandler(OnContextMenu)); MenuItemEx separator1 = new MenuItemEx("-", new EventHandler(OnContextMenu)); MenuItemEx renameGroup = new MenuItemEx("Rename Group", new EventHandler(OnContextMenu)); MenuItemEx separator2 = new MenuItemEx("-", new EventHandler(OnContextMenu)); MenuItemEx renameShortcut = new MenuItemEx("Rename Shortcut", new EventHandler(OnContextMenu)); contextMenu = new ContextMenu(); contextMenu.MenuItems.Add(0, largeIconsMenu); contextMenu.MenuItems.Add(1, smallIconsMenu); contextMenu.MenuItems.Add(2, separator1); contextMenu.MenuItems.Add(3, renameGroup); contextMenu.MenuItems.Add(4, separator2); contextMenu.MenuItems.Add(5, renameShortcut); contextMenu.Popup += new EventHandler(ContextMenuPopup); this.ContextMenu = contextMenu; }
static public MenuItem CloneMenu(MenuItemEx currentItem) { MenuItemEx clonedItem = new MenuItemEx(currentItem.Text, (Bitmap)currentItem.Icon, (Shortcut)currentItem.Shortcut, currentItem.ClickHandler); // Preserve the enable and check state clonedItem.Enabled = currentItem.Enabled; clonedItem.Checked = currentItem.Checked; clonedItem.RadioCheck = currentItem.RadioCheck; foreach (MenuItemEx item in currentItem.MenuItems) { clonedItem.MenuItems.Add(CloneMenu(item)); } return clonedItem; }