1

I want to implement visual studio style Add or Remove Ruttons toolstrip like following

enter image description here

in my winforms application, how can I achieve this?

I haven't tried anything on this as I am not sure how to start and I don't have much working experience on winforms.

Please suggest.

techBeginner
  • 3,792
  • 11
  • 43
  • 59
  • There's quie a few plugins like [this one](http://www.telerik.com/products/winforms/ribbonbar.aspx)? which has a lot of predefined stuff (quite useful actually) :) Or [this one](https://visualstudiogallery.msdn.microsoft.com/D15AE4CD-379A-41A0-BCF8-1013396175CE) – jbutler483 Nov 07 '14 at 12:22
  • @jbutler483 This is pretty easy to implement without needing to use third party software. – InBetween Nov 07 '14 at 13:20
  • @InBetween I was thinking more of styling than implementation – jbutler483 Nov 07 '14 at 13:29

1 Answers1

1

At first glance it doesn't look all that difficult.

Just add a ToolStripDropDownButton to your ToolStrip with no image or text. That will make the appearance seem more or less similar.

Add to this drop down button one ToolStripMenuItem with a "Add or Remove Buttons" caption. We'll call it AddRemoveMenuItem.

Now populate AddRemoveMenuItem's child menu items with menu items representing all your configurable ToolStripItems. You can link menu item and configurable tool strip item through the menu item's Tag property (you could also subclass ToolStripMenuItem adding a ToolStripItem LinkedToolStripItem { get; set; } property but I don't think its really worth it).

All these "linked" menu items will have to handle their Click events where they will switch their linked tool strip item's Visible property and synchronize their Checked state accordingly.

I'd do that the following way:

 linkedMenuItem.Click += (sender, e) => linkedMenuItem.Checked = !linkedMenuItem.Checked;
 linkedMenuItem.CheckedChanged +=
     (sender, e) =>
     {
         var linkedToolStripItem = linkedMenuItem.Tag as ToolStripItem;

         if (linkedToolStripItem != null)
         {
             linkedToolStripItem.Visible = linkedMenuItem.Checked;
         }
     };

When starting up your application set the linked menu items Checked state accordingly to your app's default settings, user settings, etc. and you are done.

InBetween
  • 32,319
  • 3
  • 50
  • 90