DKCheckedListBoxComboBox.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:DKCheckedListBoxComboBox.cs
  5. * 2.功能描述:下拉列表控件:可以多项选择
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/09/04 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ComponentModel;
  12. using System.Drawing;
  13. using System.Windows.Forms;
  14. namespace Dongke.IBOSS.PRD.Basics.BaseControls
  15. {
  16. /// <summary>
  17. /// 下拉列表控件:可以多项选择
  18. /// </summary>
  19. public partial class DKCheckedListBoxComboBox : PopupComboBox
  20. {
  21. #region 委托声明
  22. #endregion
  23. #region 事件声明
  24. #endregion
  25. #region 常量
  26. #endregion
  27. #region 成员变量
  28. /// <summary>
  29. /// 多选控件
  30. /// </summary>
  31. private C_CheckedListBoxEx _checkedListBox;
  32. #endregion
  33. #region 构造函数
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. public DKCheckedListBoxComboBox() : base()
  38. {
  39. InitializeComponent();
  40. this._checkedListBox = new C_CheckedListBoxEx();
  41. ListControlContainer containerControl = new ListControlContainer();
  42. containerControl.Controls.Add(_checkedListBox);
  43. containerControl.Padding = new Padding(0, 0, 0, 12);
  44. this._checkedListBox.Dock = DockStyle.Fill;
  45. this._checkedListBox.IntegralHeight = false;
  46. this.DropDownControl = containerControl;
  47. this.dropDown.Resizable = true;
  48. this._checkedListBox.ItemChecked += CheckedListBox_ItemChecked;
  49. this.dropDown.Opening += dropDown_Opening;
  50. }
  51. #endregion
  52. #region 单例模式
  53. #endregion
  54. #region 属性
  55. /// <summary>
  56. /// 获取或设置控件的数据源
  57. /// </summary>
  58. public new object DataSource
  59. {
  60. get
  61. {
  62. return this._checkedListBox.DataSource;
  63. }
  64. set
  65. {
  66. this._checkedListBox.DataSource = value;
  67. }
  68. }
  69. /// <summary>
  70. /// 获取或设置一个字符串,该字符串指定要显示其内容的列表框中所含对象的属性
  71. /// </summary>
  72. public new string DisplayMember
  73. {
  74. get
  75. {
  76. return this._checkedListBox.DisplayMember;
  77. }
  78. set
  79. {
  80. this._checkedListBox.DisplayMember = value;
  81. }
  82. }
  83. /// <summary>
  84. /// 获取或设置一个字符串,该字符串指定要从中取值的数据源的属性
  85. /// </summary>
  86. public new string ValueMember
  87. {
  88. get
  89. {
  90. return this._checkedListBox.ValueMember;
  91. }
  92. set
  93. {
  94. this._checkedListBox.ValueMember = value;
  95. }
  96. }
  97. /// <summary>
  98. ///
  99. /// </summary>
  100. [Browsable(true)]
  101. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  102. public new CheckedListBox.ObjectCollection Items
  103. {
  104. get
  105. {
  106. return this._checkedListBox.Items;
  107. }
  108. }
  109. /// <summary>
  110. ///
  111. /// </summary>
  112. [Browsable(true)]
  113. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  114. public C_CheckedListBoxEx CheckedListBox
  115. {
  116. get
  117. {
  118. return this._checkedListBox;
  119. }
  120. }
  121. public new string Text
  122. {
  123. get
  124. {
  125. return base.Text;
  126. }
  127. }
  128. #endregion
  129. #region 事件处理
  130. private void CheckedListBox_ItemChecked(object sender, ItemCheckEventArgs e)
  131. {
  132. base.Text = this._checkedListBox.GetCheckedText();
  133. }
  134. private void dropDown_Opening(object sender, CancelEventArgs e)
  135. {
  136. this._checkedListBox.ClearSelected();
  137. }
  138. #endregion
  139. #region 公有方法/函数
  140. #endregion
  141. #region 受保护方法/函数
  142. protected override void OnResize(EventArgs e)
  143. {
  144. // When the ComboBox is resized, the width of the dropdown
  145. // is also resized to match the width of the ComboBox. I think it looks better.
  146. Size Size = new Size(Width, DropDownControl.Height);
  147. dropDown.Size = Size;
  148. base.OnResize(e);
  149. }
  150. protected override void OnKeyPress(KeyPressEventArgs e)
  151. {
  152. base.OnKeyPress(e);
  153. if (copy)
  154. {
  155. copy = false;
  156. }
  157. else
  158. {
  159. e.Handled = true;
  160. }
  161. }
  162. bool copy = false;
  163. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  164. {
  165. if (keyData == (Keys.Control | Keys.C))
  166. {
  167. copy = true;
  168. return base.ProcessCmdKey(ref msg, keyData);
  169. }
  170. else
  171. {
  172. copy = false;
  173. return base.ProcessCmdKey(ref msg, keyData);
  174. }
  175. }
  176. #endregion
  177. #region 私有方法/函数
  178. #endregion
  179. }
  180. }