我想创建一个 ComboBox
勾选的下拉列表,像一个 CheckedListBox
但有一个 ComboBox
.
这个 似乎符合你的描述。
或者,像 Wyck 说。如何在c#中的combobox中添加复选框?
从我提供的第一个链接。此处, 一些 代码看起来是这样的。
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 文章,只是其中的一部分。
希望对你有所帮助:)