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?
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:
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
{
}
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 ;-)
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:
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
{
}
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
.
© 2022 - 2024 — McMap. All rights reserved.