C# 可勾选的combobox ----CheckedCombobox

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;

namespace CheckComboBoxTest {
    public class CheckedComboBox : ComboBox {

        internal class Dropdown : Form {
            internal class CCBoxEventArgs : EventArgs {
                private bool assignValues;
                public bool AssignValues {
                    get { return assignValues; }
                    set { assignValues = value; }
                }
                private EventArgs e;
                public EventArgs EventArgs {
                    get { return e; }
                    set { e = value; }
                }
                public CCBoxEventArgs(EventArgs e, bool assignValues) : base() {
                    this.e = e;
                    this.assignValues = assignValues;
                }
            }

            internal class CustomCheckedListBox : CheckedListBox {
                private int curSelIndex = -1;

                public CustomCheckedListBox() : base() {
                    this.SelectionMode = SelectionMode.One;
                    this.HorizontalScrollbar = true;                    
                }

                protected override void OnKeyDown(KeyEventArgs e) {
                    if (e.KeyCode == Keys.Enter) {
                        // Enact selection.
                        ((CheckedComboBox.Dropdown) Parent).OnDeactivate(new CCBoxEventArgs(null, true));
                        e.Handled = true;

                    } else if (e.KeyCode == Keys.Escape) {
                        ((CheckedComboBox.Dropdown) Parent).OnDeactivate(new CCBoxEventArgs(null, false));
                        e.Handled = true;

                    } else if (e.KeyCode == Keys.Delete) {
                        for (int i = 0; i < Items.Count; i++) {
                            SetItemChecked(i, e.Shift);
                        }
                        e.Handled = true;
                    }
                    base.OnKeyDown(e);
                }

                protected override void OnMouseMove(MouseEventArgs e) {
                    base.OnMouseMove(e);
                    int index = IndexFromPoint(e.Location);
                    Debug.WriteLine("Mouse over item: " + (index >= 0 ? GetItemText(Items[index]) : "None"));
                    if ((index >= 0) && (index != curSelIndex)) {
                        curSelInd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值