Example #1
0
 /// <summary>
 /// Adds the specified item.
 /// </summary>
 /// <param name="item">The item.</param>
 public abstract void Add(DropDownImageActionItem item);
Example #2
0
        public override void Add(DropDownImageActionItem item)
        {
            ToolStripDropDownButton menu;

            menu = new ToolStripDropDownButton(item.Caption)
            {
                DisplayStyle = ToolStripItemDisplayStyle.Image,
                Image        = item.SelectedItem
            };

            menu.Name    = item.Key;
            menu.Enabled = item.Enabled;
            menu.Visible = item.Visible;

            System.Drawing.Image[] subImages = item.Items;
            string[] subHints       = item.Hints;
            int      iSubItemsCount = subImages.Length;

            for (int iIndex = 0; iIndex < iSubItemsCount; iIndex++)
            {
                System.Drawing.Image imageThere = subImages[iIndex];
                if (imageThere != item.SelectedItem)
                {
                    ToolStripItem subItem = menu.DropDownItems.Add(subImages[iIndex]);
                    subItem.ToolTipText = subHints[iIndex];
                    subItem.Click      += (s, a) => item.SelectedItem = subItem.Image;
                }
                else
                {
                    menu.ToolTipText = subHints[iIndex];
                }
            }

            EnsureNonNullRoot(item);
            var root = _menuStrip.Items[item.RootKey] as ToolStripDropDownButton;

            if (root == null)
            {
                // Temporarily create the root.
                root = CreateToolStripDropDownButton(new RootItem(item.RootKey, "AddRootItemWithKey " + item.RootKey));
            }

            if (item.MenuContainerKey == null)
            {
                var strip = GetOrCreateStrip(item.GroupCaption);
                if (strip != null)
                {
                    strip.Items.Add(menu);
                }
                menu.ToolTipText = String.IsNullOrWhiteSpace(item.ToolTipText) == false ? item.ToolTipText : item.Caption;
            }
            else
            {
                var subMenu = root.DropDownItems[item.MenuContainerKey] as ToolStripMenuItem;
                if (subMenu != null)
                {
                    subMenu.DropDownItems.Add(menu);
                }
            }

            item.PropertyChanged += DropDownImageActionItemPropertyChanged;
        }