有没有办法让一个组合框有一个选中的下拉列表?C# [重复]

问题描述 投票:-2回答:1

我想创建一个 ComboBox 勾选的下拉列表,像一个 CheckedListBox但有一个 ComboBox.

c# .net winforms combobox checkedlistbox
1个回答
0
投票

这个 似乎符合你的描述。

或者,像 Wyck 说。如何在c#中的combobox中添加复选框?

来自 拉里的回答。Wyck, 这个这个 看起来不错。

从我提供的第一个链接。此处, 一些 代码看起来是这样的。

protected override void OnDropDown(EventArgs e) {
    base.OnDropDown(e);
    DoDropDown();    
}

private void DoDropDown() {
    if (!dropdown.Visible) {
        Rectangle rect = RectangleToScreen(this.ClientRectangle);
        dropdown.Location = new Point(rect.X, rect.Y + this.Size.Height);
        int count = dropdown.List.Items.Count;
        if (count > this.MaxDropDownItems) {
            count = this.MaxDropDownItems;
        } else if (count == 0) {
            count = 1;
        }
        dropdown.Size = new Size(this.Size.Width, 
                       (dropdown.List.ItemHeight + 1) * count);
        dropdown.Show(this);
    }
}

protected override void OnKeyDown(KeyEventArgs e) {
    if (e.KeyCode == Keys.Down) {        
        OnDropDown(null);
    }
    // Make sure that certain keys or combinations are not blocked.
    e.Handled = !e.Alt && !(e.KeyCode == Keys.Tab) &&
        !((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right) || 
    (e.KeyCode == Keys.Home) || (e.KeyCode == Keys.End));
    base.OnKeyDown(e);
}

protected override void OnKeyPress(KeyPressEventArgs e) {
    e.Handled = true;
    base.OnKeyPress(e);
}

protected override void OnDeactivate(EventArgs e) {
base.OnDeactivate(e);
CCBoxEventArgs ce = e as CCBoxEventArgs;
if (ce != null) {
    CloseDropdown(ce.AssignValues);
} else {

    CloseDropdown(true);
}
}

这是 所需的代码,从 CodeProject 文章,只是其中的一部分。

希望对你有所帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.