private void CreateResourceDropDownMenu() { List <ToolStripMenuItem> items = new List <ToolStripMenuItem>(); foreach (string resourceType in Context.ResourceTypes.Select(n => n.Name)) { ToolStripMenuItem menuItem = null; try { menuItem = new ToolStripMenuItem(resourceType) { Name = resourceType + "_menuItem", Image = IconManager.Instance.VirtualResourceIcons.Images[resourceType], Tag = ConfigurationObjectTag.Create(EnumUtil.Parse <VirtualResourceType>(resourceType)) }; menuItem.Click += newResource_MenuItem_Click; items.Add(menuItem); } catch { menuItem?.Dispose(); throw; } } foreach (ToolStripMenuItem item in items.OrderBy(n => n.Name)) { addResource_ToolStripDropDownButton.DropDownItems.Add(item); } }
private void CreateActivityDropDownMenu() { List <ToolStripMenuItem> items = new List <ToolStripMenuItem>(); foreach (MetadataType type in GetMetadataTypes(VirtualResourceType.LoadTester)) { string typeName = type.Name; ToolStripMenuItem menuItem = new ToolStripMenuItem(type.Title); menuItem.Name = typeName + "_menuItem"; menuItem.Image = IconManager.Instance.PluginIcons.Images[typeName]; menuItem.Tag = ConfigurationObjectTag.Create(VirtualResourceType.LoadTester, typeName); menuItem.Click += new EventHandler(newActivity_MenuItem_Click); // Determine whether this item should be added to a sub-menu if (string.IsNullOrEmpty(type.Group)) { items.Add(menuItem); } else { // See if the sub-menu alrady exists ToolStripMenuItem subMenu = items.FirstOrDefault(n => n.Text == type.Group); if (subMenu == null) { subMenu = new ToolStripMenuItem(type.Group); items.Add(subMenu); } subMenu.DropDownItems.Add(menuItem); } } newActivity_ToolStripDropDownButton.DropDownItems.AddRange(items.OrderBy(n => n.Text).ToArray()); }