在C#,VS2008中隐藏ComboBox中的箭头按钮

时间:2012-01-05 10:03:36

标签: c# winforms visual-studio-2008 combobox

我需要隐藏ComboBox的箭头按钮。

我希望DropDownStyle属性等于ComboBoxStyle.DropDownList,而不会显示下拉箭头。我能这样做吗?

我可以使用其他控件来显示图像的下拉列表吗?

感谢您的帮助。

5 个答案:

答案 0 :(得分:2)

你可以尝试伪造它。用Textbox覆盖它并在Textbox's GotFocus()事件中,只需设置comboBox.Focus()

答案 1 :(得分:0)

您可以创建扩展控件,或者可以为此目的覆盖表单中的组合框的绘制事件

答案 2 :(得分:0)

您可以使用弹出控件显示所需内容。

对于WPF:Popup Control at MSDN

对于Winform:Simple Popup at CodeProject.com

答案 3 :(得分:0)

尝试设置DropDownStyle = Simple和Height只显示一行(约24px)。

答案 4 :(得分:0)

对于WinForms,您可能喜欢基于一个按钮的此类,该按钮会在上下文菜单中弹出您的项目,然后将所选项目的文本用作按钮文本:

public class DropList : Button
{
    public event EventHandler TextChangedByUser;
    private ContextMenu _CM = new ContextMenu();
    private string[] _Items;

    public string[] Items
    {
        get { return _Items; }
        set
        {
            _Items = value;
            _CM.MenuItems.Clear();
            foreach (string sChoice in _Items)
            {
                MenuItem MI = _CM.MenuItems.Add(sChoice, MI_Click);
            }
        }
    }

    private void MI_Click(object sender, EventArgs e)
    {
        if (this.Text != (sender as MenuItem).Text)
        {
            this.Text = (sender as MenuItem).Text;
            if (TextChangedByUser != null) TextChangedByUser.Invoke(this, new EventArgs());
        }
    }

    protected override void OnClick(EventArgs e)
    {
        base.OnClick(e);
        _CM.Show(this, new System.Drawing.Point(0, this.Height - 1));
    }
}
相关问题