Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I embed a ComboBox and a simple Button into a StatusStrip in WinForms?

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?

like image 371
Ivan Avatar asked Feb 12 '11 15:02

Ivan


3 Answers

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 ;-)

like image 197
Andrea Antonangeli Avatar answered Nov 02 '22 00:11

Andrea Antonangeli


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
 {
 }
like image 14
digEmAll Avatar answered Nov 02 '22 00:11

digEmAll


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.

like image 1
DavidRR Avatar answered Nov 02 '22 00:11

DavidRR