本文介绍了我可以嵌入一个组合框和一个简单的按钮到StatusStrip中的的WinForms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下组合框和按钮元素并不在那些表示愿意加入到一个StatusStrip中通过的WinForms设计师(而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?

推荐答案

您可以轻松实现从<$c$c>ToolStripControlHost:

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。
此项目将也可用在的ContextMenuStrip 的MenuStrip

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

编辑:

要设置自定义图标<$c$c>ToolboxBitmapAttribute.

To set a custom icon use ToolboxBitmapAttribute.

不过,我注意到,居然还有叫一个内置的组合框工具条项目 ToolStripComboBox
它只是没有设计师的知名度为StatusStrip中,但它可以很容易地添加到StatusStrip中由code,或者,如果你preFER,你可以扩展它赋予完整的可见性:

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
 {
 }

这篇关于我可以嵌入一个组合框和一个简单的按钮到StatusStrip中的的WinForms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 23:07