C_StatusCheckBox.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. public C_StatusCheckBox(bool chktrueselect, bool chkflaseselect)
  65. {
  66. InitializeComponent();
  67. if (chktrueselect == true)
  68. {
  69. this.chkTrue.Checked = true;
  70. }
  71. if (chkflaseselect == true)
  72. {
  73. this.chkFalse.Checked = true;
  74. }
  75. }
  76. #endregion
  77. #region 属性
  78. /// <summary>
  79. /// 获取或者设定标签的内容
  80. /// </summary>
  81. [Description("获取或者设定标签的内容。")]
  82. public string Title
  83. {
  84. get
  85. {
  86. return this.lblTitle.Text;
  87. }
  88. set
  89. {
  90. this.lblTitle.Text = value;
  91. AdjustControl();
  92. }
  93. }
  94. /// <summary>
  95. /// 获取或者设定第一个复选框的文本内容
  96. /// </summary>
  97. [Description("获取或者设定第一个复选框的文本内容。")]
  98. public string TrueText
  99. {
  100. get
  101. {
  102. return this.chkTrue.Text;
  103. }
  104. set
  105. {
  106. this.chkTrue.Text = value;
  107. AdjustControl();
  108. }
  109. }
  110. /// <summary>
  111. /// 获取或者设定第二个复选框的文本内容
  112. /// </summary>
  113. [Description("获取或者设定第二个复选框的文本内容。")]
  114. public string FalseText
  115. {
  116. get
  117. {
  118. return this.chkFalse.Text;
  119. }
  120. set
  121. {
  122. this.chkFalse.Text = value;
  123. AdjustControl();
  124. }
  125. }
  126. /// <summary>
  127. /// 获取或者设定标签的对齐方式
  128. /// </summary>
  129. [Description("获取或者设定标签的对齐方式。")]
  130. [DefaultValue(System.Drawing.ContentAlignment.MiddleRight)]
  131. [Localizable(true)]
  132. public ContentAlignment TitleAlign
  133. {
  134. get
  135. {
  136. return this.lblTitle.TextAlign;
  137. }
  138. set
  139. {
  140. this.lblTitle.TextAlign = value;
  141. }
  142. }
  143. ///// <summary>
  144. ///// 获取或者设定控件是否可用
  145. ///// </summary>
  146. //public new bool Enabled
  147. //{
  148. // get
  149. // {
  150. // return this.checkedListBox.Enabled;
  151. // }
  152. // set
  153. // {
  154. // this.lblTitle.Enabled = value;
  155. // this.checkedListBox.Enabled = value;
  156. // this.TabStop = value;
  157. // }
  158. //}
  159. /// <summary>
  160. /// 获取或者设定选中的项目
  161. /// </summary>
  162. [Description("获取或者设定选中的项目。")]
  163. public Object[] SelectedValues
  164. {
  165. get
  166. {
  167. Object[] selectedValue = new Object[2];
  168. if (this.chkTrue.Checked && !this.chkFalse.Checked)
  169. {
  170. return new Object[] { 1 };
  171. }
  172. else if (!this.chkTrue.Checked && this.chkFalse.Checked)
  173. {
  174. return new Object[] { 0 };
  175. }
  176. else if (this.chkTrue.Checked && this.chkFalse.Checked)
  177. {
  178. return new Object[] { 1, 0 };
  179. }
  180. else
  181. {
  182. return new Object[] { };
  183. }
  184. }
  185. }
  186. /// <summary>
  187. /// 获取或者设定控件的字体
  188. /// </summary>
  189. public new Font Font
  190. {
  191. get
  192. {
  193. return base.Font;
  194. }
  195. set
  196. {
  197. base.Font = value;
  198. this.lblTitle.Font = value;
  199. this.chkTrue.Font = value;
  200. this.chkFalse.Font = value;
  201. }
  202. }
  203. #endregion
  204. #region 公开方法或者函数
  205. ///// <summary>
  206. ///// BeginUpdate
  207. ///// </summary>
  208. //public void BeginUpdate()
  209. //{
  210. // this.checkedListBox.BeginUpdate();
  211. //}
  212. ///// <summary>
  213. ///// EndUpdate
  214. ///// </summary>
  215. //public void EndUpdate()
  216. //{
  217. // this.checkedListBox.EndUpdate();
  218. //}
  219. ///// <summary>
  220. ///// 往项目列表中追加指定项目
  221. ///// </summary>
  222. ///// <param name="item">指定项目</param>
  223. //public void Add(CheckedBoxListItem item)
  224. //{
  225. // checkedListBox.Add(item);
  226. //}
  227. ///// <summary>
  228. ///// 移动指定的项目
  229. ///// </summary>
  230. ///// <param name="item">指定的项目</param>
  231. //public void Remove(CheckedBoxListItem item)
  232. //{
  233. // checkedListBox.Items.Remove(item);
  234. //}
  235. ///// <summary>
  236. ///// 移除所有的项目
  237. ///// </summary>
  238. //public void RemoveAll()
  239. //{
  240. // checkedListBox.Items.Clear();
  241. //}
  242. /// <summary>
  243. /// 清除所有项目的选中状态
  244. /// </summary>
  245. public void ClearItemCheck()
  246. {
  247. this.chkTrue.Checked = false;
  248. this.chkFalse.Checked = false;
  249. }
  250. /// <summary>
  251. /// 将所有项目选中状态
  252. /// </summary>
  253. public void AllItemCheck()
  254. {
  255. this.chkTrue.Checked = true;
  256. this.chkFalse.Checked = true;
  257. }
  258. ///// <summary>
  259. ///// 根据项目索引和标识设定项目的选中状态
  260. ///// </summary>
  261. ///// <param name="index">项目索引</param>
  262. ///// <param name="flg">选中与否标识</param>
  263. //public void SetSelected(int index, bool flg)
  264. //{
  265. // checkedListBox.SetSelected(index, flg);
  266. //}
  267. ///// <summary>
  268. ///// 根据项目的索引取得项目选中状态
  269. ///// </summary>
  270. ///// <param name="index">项目的索引</param>
  271. ///// <returns></returns>
  272. //public bool GetItemChecked(int index)
  273. //{
  274. // return checkedListBox.GetItemChecked(index);
  275. //}
  276. #endregion
  277. #region 受保护方法或者函数
  278. /// <summary>
  279. /// 自动计算并调整控件的位置
  280. /// </summary>
  281. protected void AdjustControl()
  282. {
  283. //if (LablePositionValue == LablePosition.Left)
  284. //{
  285. this.lblTitle.Location = new System.Drawing.Point(0, 0);
  286. this.chkTrue.Location = new System.Drawing.Point(this.lblTitle.Width +
  287. ControlsConst.CONTROLSPACE, 0);
  288. this.chkTrue.Size = new System.Drawing.Size(
  289. this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
  290. this.chkFalse.Location = new System.Drawing.Point(this.lblTitle.Width
  291. + this.chkTrue.Width + ControlsConst.CONTROLSPACE, 0);
  292. this.chkFalse.Size = new System.Drawing.Size(
  293. this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
  294. //this.checkedListBox.Location = new System.Drawing.Point(this.lblTitle.Width +
  295. // ControlsConst.CONTROLSPACE, 0);
  296. //this.checkedListBox.Size = new System.Drawing.Size(
  297. // this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
  298. //}
  299. //else if (LablePositionValue == LablePosition.Top)
  300. //{
  301. // this.lblTitle.Location = new System.Drawing.Point(0, 0);
  302. // this.checkedListBox.Location = new System.Drawing.Point(0, this.lblTitle.Height +
  303. // ControlsConst.CONTROLSPACE);
  304. // this.checkedListBox.Size = new System.Drawing.Size(this.Width,
  305. // this.Height - this.lblTitle.Height - ControlsConst.CONTROLSPACE);
  306. //}
  307. }
  308. #endregion
  309. #region 控件事件
  310. /// <summary>
  311. /// 控件的尺寸改变时发生的事件
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void CheckedBoxListEx_SizeChanged(object sender, EventArgs e)
  316. {
  317. AdjustControl();
  318. }
  319. ///// <summary>
  320. ///// 离开控件时发生的事件
  321. ///// </summary>
  322. ///// <param name="sender"></param>
  323. ///// <param name="e"></param>
  324. //private void CheckedBoxListEx_Leave(object sender, EventArgs e)
  325. //{
  326. // this.checkedListBox.SelectedIndex = -1;
  327. //}
  328. #endregion
  329. }
  330. }