11

By default ComboBox and Button elements are not among those offered to add into a StatusStrip by WinForms designer (while DropDownButton and SplitButton are). Is there a way to add them there? As far as I've heard any control can be embedded there, but how?

Ivan
  • 63,011
  • 101
  • 250
  • 382
  • Why are not you satisfied with the proposed ones? – Sasha Reminnyi Feb 12 '11 at 15:31
  • 1
    Proposed what? There is no ComboBox analogue offered for embedding into StatusStrip (a ComboBox is a drop-down list with a user-editable text field - I need a user to be able to enter text there), neither is TextBox (which I could use instead by combining it with a DropDownButton). – Ivan Feb 12 '11 at 16:06

3 Answers3

22

More easily, you can cut a ToolStripComboBox created via the menu in a ToolStrip and paste it in the StatusStrip. No lines of code written... and it works ;-)

Andrea Antonangeli
  • 1,242
  • 1
  • 21
  • 32
15

You can implement easily inheriting from ToolStripControlHost:

[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip |
                                       ToolStripItemDesignerAvailability.ContextMenuStrip | 
                                       ToolStripItemDesignerAvailability.StatusStrip)]
    public class ComboStripItem : ToolStripControlHost
    {
        private ComboBox combo;

        public ComboStripItem()
            : base(new ComboBox())
        {
            this.combo = this.Control as ComboBox;
        }

        // Add properties, events etc. you want to expose...
    }

After rebuilding your solution you will able to see the item even in the designer:

ComboStripItem in forms designer

P.S.
this item will be usable also in ContextMenuStrip and in MenuStrip.

EDIT:

To set a custom icon use ToolboxBitmapAttribute.

However, I noticed that actually there's a built-in combobox toolstrip item called ToolStripComboBox.
It has just no designer visibility for the StatusStrip , but it can be easily added to a StatusStrip by code, or, if you prefer, you can extend it giving the complete visibility:

 [ToolboxBitmapAttribute("image path or use another overload..."),
  ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip |
                                   ToolStripItemDesignerAvailability.ContextMenuStrip |
                                   ToolStripItemDesignerAvailability.StatusStrip)]
 public class ComboBoxItem : ToolStripComboBox
 {
 }
digEmAll
  • 56,430
  • 9
  • 115
  • 140
  • Damn - this is golded. Been stumbling around in this for a few days and those attribute tags are a godsend! – stigzler Mar 26 '23 at 18:57
1

If you want to add a simple button to your StatusStrip, you can do so using the Designer.

First, add a DropDownButton. Then, in the DropDownButton properties window, set the ShowDropDownArrow property to False.

Repeat for each additional simple button that you want to show in your StatusStrip.

DavidRR
  • 18,291
  • 25
  • 109
  • 191