我可以将 ComboBox 和简单的 Button 嵌入到 WinForms 的 StatusStrip 中吗?
默认情况下,ComboBox 和 Button 元素不属于 WinForms 设计器提供的添加到 StatusStrip 中的元素(而 DropDownButton 和 SplitButton 则属于)。有没有办法将它们添加到那里?据我所知,任何控件都可以嵌入其中,但是如何嵌入呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更容易的是,您可以剪切通过 ToolStrip 中的菜单创建的 ToolStripComboBox,并将其粘贴到 StatusStrip 中。
没有写任何代码行...并且它可以工作;-)
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 ;-)
您可以轻松实现从
ToolStripControlHost
继承:重建解决方案后,您甚至可以在设计器中看到该项目:
PS
该项目也可在
ContextMenuStrip
和MenuStrip
中使用。编辑:
要设置自定义图标,请使用
ToolboxBitmapAttribute
。但是,我注意到实际上有一个名为
ToolStripComboBox
的内置组合框工具条项。它对 StatusStrip 没有设计者可见性,但可以通过代码轻松地将其添加到 StatusStrip,或者,如果您愿意,您可以扩展它以提供完整的可见性:
You can implement easily inheriting from
ToolStripControlHost
: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 inMenuStrip
.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:
如果您想向
StatusStrip
添加简单按钮,可以使用设计器来实现。首先,添加一个
DropDownButton
。然后,在DropDownButton
属性窗口中,将ShowDropDownArrow
属性设置为False
。对您想要在
StatusStrip
中显示的每个其他简单按钮重复此操作。If you want to add a simple button to your
StatusStrip
, you can do so using the Designer.First, add a
DropDownButton
. Then, in theDropDownButton
properties window, set theShowDropDownArrow
property toFalse
.Repeat for each additional simple button that you want to show in your
StatusStrip
.