C_StatusCheckBox.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:C_StatusCheckBox.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 C_StatusCheckBox : UserControl
  20. {
  21. #region 事件
  22. ///// <summary>
  23. ///// 在鼠标捕获更改后发生
  24. ///// </summary>
  25. //[Description("在鼠标捕获更改后发生。")]
  26. //public new event EventHandler MouseCaptureChanged
  27. //{
  28. // add
  29. // {
  30. // this.checkedListBox.MouseCaptureChanged += value;
  31. // }
  32. // remove
  33. // {
  34. // this.checkedListBox.MouseCaptureChanged -= value;
  35. // }
  36. //}
  37. ///// <summary>
  38. ///// 指示某项的选中状态将要更改。直到事件发生后,该值才会更新
  39. ///// </summary>
  40. //[Description("指示某项的选中状态将要更改。直到事件发生后,该值才会更新。")]
  41. //public event ItemCheckEventHandler ItemCheck
  42. //{
  43. // add
  44. // {
  45. // this.checkedListBox.ItemCheck += value;
  46. // }
  47. // remove
  48. // {
  49. // this.checkedListBox.ItemCheck -= value;
  50. // }
  51. //}
  52. #endregion
  53. #region 成员变量
  54. // 显示的值
  55. private string _displayMember = string.Empty;
  56. // 实际的值
  57. private string _valueMember = string.Empty;
  58. #endregion
  59. #region 构造函数
  60. public C_StatusCheckBox()
  61. {
  62. InitializeComponent();
  63. }
  64. #endregion
  65. #region 属性
  66. /// <summary>
  67. /// 获取或者设定标签的内容
  68. /// </summary>
  69. [Description("获取或者设定标签的内容。")]
  70. public string Title
  71. {
  72. get
  73. {
  74. return this.lblTitle.Text;
  75. }
  76. set
  77. {
  78. this.lblTitle.Text = value;
  79. AdjustControl();
  80. }
  81. }
  82. /// <summary>
  83. /// 获取或者设定第一个复选框的文本内容
  84. /// </summary>
  85. [Description("获取或者设定第一个复选框的文本内容。")]
  86. public string TrueText
  87. {
  88. get
  89. {
  90. return this.chkTrue.Text;
  91. }
  92. set
  93. {
  94. this.chkTrue.Text = value;
  95. AdjustControl();
  96. }
  97. }
  98. /// <summary>
  99. /// 获取或者设定第二个复选框的文本内容
  100. /// </summary>
  101. [Description("获取或者设定第二个复选框的文本内容。")]
  102. public string FalseText
  103. {
  104. get
  105. {
  106. return this.chkFalse.Text;
  107. }
  108. set
  109. {
  110. this.chkFalse.Text = value;
  111. AdjustControl();
  112. }
  113. }
  114. /// <summary>
  115. /// 获取或者设定标签的对齐方式
  116. /// </summary>
  117. [Description("获取或者设定标签的对齐方式。")]
  118. [DefaultValue(System.Drawing.ContentAlignment.MiddleRight)]
  119. [Localizable(true)]
  120. public ContentAlignment TitleAlign
  121. {
  122. get
  123. {
  124. return this.lblTitle.TextAlign;
  125. }
  126. set
  127. {
  128. this.lblTitle.TextAlign = value;
  129. }
  130. }
  131. ///// <summary>
  132. ///// 获取或者设定控件是否可用
  133. ///// </summary>
  134. //public new bool Enabled
  135. //{
  136. // get
  137. // {
  138. // return this.checkedListBox.Enabled;
  139. // }
  140. // set
  141. // {
  142. // this.lblTitle.Enabled = value;
  143. // this.checkedListBox.Enabled = value;
  144. // this.TabStop = value;
  145. // }
  146. //}
  147. /// <summary>
  148. /// 获取或者设定选中的项目
  149. /// </summary>
  150. [Description("获取或者设定选中的项目。")]
  151. public Object[] SelectedValues
  152. {
  153. get
  154. {
  155. Object[] selectedValue = new Object[2];
  156. if (this.chkTrue.Checked && !this.chkFalse.Checked)
  157. {
  158. return new Object[] { 1 };
  159. }
  160. else if (!this.chkTrue.Checked && this.chkFalse.Checked)
  161. {
  162. return new Object[] { 0 };
  163. }
  164. else if (this.chkTrue.Checked && this.chkFalse.Checked)
  165. {
  166. return new Object[] { 1, 0 };
  167. }
  168. else
  169. {
  170. return new Object[] { };
  171. }
  172. }
  173. }
  174. /// <summary>
  175. /// 获取或者设定控件的字体
  176. /// </summary>
  177. public new Font Font
  178. {
  179. get
  180. {
  181. return base.Font;
  182. }
  183. set
  184. {
  185. base.Font = value;
  186. this.lblTitle.Font = value;
  187. this.chkTrue.Font = value;
  188. this.chkFalse.Font = value;
  189. }
  190. }
  191. #endregion
  192. #region 公开方法或者函数
  193. ///// <summary>
  194. ///// BeginUpdate
  195. ///// </summary>
  196. //public void BeginUpdate()
  197. //{
  198. // this.checkedListBox.BeginUpdate();
  199. //}
  200. ///// <summary>
  201. ///// EndUpdate
  202. ///// </summary>
  203. //public void EndUpdate()
  204. //{
  205. // this.checkedListBox.EndUpdate();
  206. //}
  207. ///// <summary>
  208. ///// 往项目列表中追加指定项目
  209. ///// </summary>
  210. ///// <param name="item">指定项目</param>
  211. //public void Add(CheckedBoxListItem item)
  212. //{
  213. // checkedListBox.Add(item);
  214. //}
  215. ///// <summary>
  216. ///// 移动指定的项目
  217. ///// </summary>
  218. ///// <param name="item">指定的项目</param>
  219. //public void Remove(CheckedBoxListItem item)
  220. //{
  221. // checkedListBox.Items.Remove(item);
  222. //}
  223. ///// <summary>
  224. ///// 移除所有的项目
  225. ///// </summary>
  226. //public void RemoveAll()
  227. //{
  228. // checkedListBox.Items.Clear();
  229. //}
  230. /// <summary>
  231. /// 清除所有项目的选中状态
  232. /// </summary>
  233. public void ClearItemCheck()
  234. {
  235. this.chkTrue.Checked = false;
  236. this.chkFalse.Checked = false;
  237. }
  238. /// <summary>
  239. /// 将所有项目选中状态
  240. /// </summary>
  241. public void AllItemCheck()
  242. {
  243. this.chkTrue.Checked = true;
  244. this.chkFalse.Checked = true;
  245. }
  246. ///// <summary>
  247. ///// 根据项目索引和标识设定项目的选中状态
  248. ///// </summary>
  249. ///// <param name="index">项目索引</param>
  250. ///// <param name="flg">选中与否标识</param>
  251. //public void SetSelected(int index, bool flg)
  252. //{
  253. // checkedListBox.SetSelected(index, flg);
  254. //}
  255. ///// <summary>
  256. ///// 根据项目的索引取得项目选中状态
  257. ///// </summary>
  258. ///// <param name="index">项目的索引</param>
  259. ///// <returns></returns>
  260. //public bool GetItemChecked(int index)
  261. //{
  262. // return checkedListBox.GetItemChecked(index);
  263. //}
  264. #endregion
  265. #region 受保护方法或者函数
  266. /// <summary>
  267. /// 自动计算并调整控件的位置
  268. /// </summary>
  269. protected void AdjustControl()
  270. {
  271. //if (LablePositionValue == LablePosition.Left)
  272. //{
  273. this.lblTitle.Location = new System.Drawing.Point(0, 0);
  274. this.chkTrue.Location = new System.Drawing.Point(this.lblTitle.Width +
  275. ControlsConst.CONTROLSPACE, 0);
  276. this.chkTrue.Size = new System.Drawing.Size(
  277. this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
  278. this.chkFalse.Location = new System.Drawing.Point(this.lblTitle.Width
  279. + this.chkTrue.Width + ControlsConst.CONTROLSPACE, 0);
  280. this.chkFalse.Size = new System.Drawing.Size(
  281. this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
  282. //this.checkedListBox.Location = new System.Drawing.Point(this.lblTitle.Width +
  283. // ControlsConst.CONTROLSPACE, 0);
  284. //this.checkedListBox.Size = new System.Drawing.Size(
  285. // this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
  286. //}
  287. //else if (LablePositionValue == LablePosition.Top)
  288. //{
  289. // this.lblTitle.Location = new System.Drawing.Point(0, 0);
  290. // this.checkedListBox.Location = new System.Drawing.Point(0, this.lblTitle.Height +
  291. // ControlsConst.CONTROLSPACE);
  292. // this.checkedListBox.Size = new System.Drawing.Size(this.Width,
  293. // this.Height - this.lblTitle.Height - ControlsConst.CONTROLSPACE);
  294. //}
  295. }
  296. #endregion
  297. #region 控件事件
  298. /// <summary>
  299. /// 控件的尺寸改变时发生的事件
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void CheckedBoxListEx_SizeChanged(object sender, EventArgs e)
  304. {
  305. AdjustControl();
  306. }
  307. ///// <summary>
  308. ///// 离开控件时发生的事件
  309. ///// </summary>
  310. ///// <param name="sender"></param>
  311. ///// <param name="e"></param>
  312. //private void CheckedBoxListEx_Leave(object sender, EventArgs e)
  313. //{
  314. // this.checkedListBox.SelectedIndex = -1;
  315. //}
  316. #endregion
  317. }
  318. }