Example #1
0
        /// <summary>
        /// Make a ToolStrip, which contains all the provided <paramref name="menuIds"/> and uses the provided <paramref name="commandHandler"/>
        /// </summary>
        /// <param name="menuIds">menu ids to display in thei toolstrip</param>
        /// <param name="commandHandler">command handler to handle the clicks on the buttons</param>
        /// <returns></returns>
        public static ToolStrip MakeToolStrip(string[] menuIds, string name, ICommandHandler commandHandler)
        {   // there are two kinds of buttons: simple buttons (ToolStripButton), which immediately execute the command when clicked and
            // combo buttons (ToolStripSplitButton), which show a popup menu when clicked. The latter also may change their image to
            // display the last clicked menu item: if so, on click, they execute the last clicked menu item, if not, the show the popup menu.
            ToolStrip res = new ToolStrip();

            res.Name = name;
            for (int i = 0; i < menuIds.Length; i++)
            {
                int ImageIndex = MenuResource.FindImageIndex(menuIds[i]);
                if (MenuResource.IsPopup(menuIds[i])) // this is a popup menu id. On click, we show the popup menu (sub menu)
                {
                    ToolStripSplitButton btn = new ToolStripSplitButton();
                    TagInfo tagInfo          = new TagInfo(menuIds[i], commandHandler, btn, true);
                    btn.Tag = tagInfo;
                    if (ImageIndex >= 0)
                    {
                        btn.DisplayStyle = ToolStripItemDisplayStyle.Image;
                        btn.ImageScaling = ToolStripItemImageScaling.None;
                        btn.Image        = ButtonImages.ButtonImageList.Images[ImageIndex];
                    }
                    else
                    {
                        btn.DisplayStyle = ToolStripItemDisplayStyle.Text;
                    }
                    btn.Name   = StringTable.GetString(menuIds[i]); // not sure, what the name is used for
                    btn.Size   = new System.Drawing.Size(24, 24);
                    btn.Text   = StringTable.GetString(menuIds[i]);
                    btn.Click += tagInfo.ButtonClicked;
                    res.Items.Add(btn);
                }
                else
                {
                    ToolStripButton btn     = new ToolStripButton();
                    TagInfo         tagInfo = new TagInfo(menuIds[i], commandHandler, btn);
                    btn.Tag = tagInfo;
                    if (ImageIndex >= 0)
                    {
                        btn.DisplayStyle = ToolStripItemDisplayStyle.Image;
                        btn.ImageScaling = ToolStripItemImageScaling.None;
                        btn.Image        = ButtonImages.ButtonImageList.Images[ImageIndex];
                    }
                    else
                    {
                        btn.DisplayStyle = ToolStripItemDisplayStyle.Text;
                    }
                    btn.Name   = StringTable.GetString(menuIds[i]);
                    btn.Size   = new System.Drawing.Size(24, 24);
                    btn.Text   = StringTable.GetString(menuIds[i]); // will be shown as a tooltip
                    btn.Click += tagInfo.ButtonClicked;
                    res.Items.Add(btn);
                }
            }
            return(res);
        }
Example #2
0
 bool ICommandHandler.OnCommand(string MenuId)
 {   // ToolStripSplitButton create a popup menu, which is directed to this tag.
     // The ToolStripSplitButton contains the icon of the last selected menu item of the sub menu,
     // which will be used, when the button (and not the drop down part) of the ToolStripSplitButton is clicked.
     if (showLastSubMenu)
     {
         lastSubMenuId = MenuId;
         int ImageIndex = MenuResource.FindImageIndex(MenuId);
         if (ImageIndex >= 0)
         {
             parent.Image = ButtonImages.ButtonImageList.Images[ImageIndex];
         }
     }
     return(commandHandler.OnCommand(MenuId));
 }