/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:DKCheckedListBoxComboBox.cs * 2.功能描述:下拉列表控件:可以多项选择 * 编辑履历: * 作者 日期 版本 修改内容 * 陈晓野 2014/09/04 1.00 新建 *******************************************************************************/ using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace Dongke.IBOSS.PRD.Basics.BaseControls { /// /// 下拉列表控件:可以多项选择 /// public partial class DKCheckedListBoxComboBox : PopupComboBox { #region 委托声明 #endregion #region 事件声明 #endregion #region 常量 #endregion #region 成员变量 /// /// 多选控件 /// private C_CheckedListBoxEx _checkedListBox; #endregion #region 构造函数 /// /// 构造函数 /// public DKCheckedListBoxComboBox() : base() { InitializeComponent(); this._checkedListBox = new C_CheckedListBoxEx(); ListControlContainer containerControl = new ListControlContainer(); containerControl.Controls.Add(_checkedListBox); containerControl.Padding = new Padding(0, 0, 0, 12); this._checkedListBox.Dock = DockStyle.Fill; this._checkedListBox.IntegralHeight = false; this.DropDownControl = containerControl; this.dropDown.Resizable = true; this._checkedListBox.ItemChecked += CheckedListBox_ItemChecked; this.dropDown.Opening += dropDown_Opening; } #endregion #region 单例模式 #endregion #region 属性 /// /// 获取或设置控件的数据源 /// public new object DataSource { get { return this._checkedListBox.DataSource; } set { this._checkedListBox.DataSource = value; } } /// /// 获取或设置一个字符串,该字符串指定要显示其内容的列表框中所含对象的属性 /// public new string DisplayMember { get { return this._checkedListBox.DisplayMember; } set { this._checkedListBox.DisplayMember = value; } } /// /// 获取或设置一个字符串,该字符串指定要从中取值的数据源的属性 /// public new string ValueMember { get { return this._checkedListBox.ValueMember; } set { this._checkedListBox.ValueMember = value; } } /// /// /// [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public new CheckedListBox.ObjectCollection Items { get { return this._checkedListBox.Items; } } /// /// /// [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public C_CheckedListBoxEx CheckedListBox { get { return this._checkedListBox; } } public new string Text { get { return base.Text; } } #endregion #region 事件处理 private void CheckedListBox_ItemChecked(object sender, ItemCheckEventArgs e) { base.Text = this._checkedListBox.GetCheckedText(); } private void dropDown_Opening(object sender, CancelEventArgs e) { this._checkedListBox.ClearSelected(); } #endregion #region 公有方法/函数 #endregion #region 受保护方法/函数 protected override void OnResize(EventArgs e) { // When the ComboBox is resized, the width of the dropdown // is also resized to match the width of the ComboBox. I think it looks better. Size Size = new Size(Width, DropDownControl.Height); dropDown.Size = Size; base.OnResize(e); } protected override void OnKeyPress(KeyPressEventArgs e) { base.OnKeyPress(e); if (copy) { copy = false; } else { e.Handled = true; } } bool copy = false; protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Control | Keys.C)) { copy = true; return base.ProcessCmdKey(ref msg, keyData); } else { copy = false; return base.ProcessCmdKey(ref msg, keyData); } } #endregion #region 私有方法/函数 #endregion } }