| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:C_StatusCheckBox.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
- {
- /// <summary>
- /// 扩展的复选框列表控件:可以多项选择
- /// </summary>
- public partial class C_StatusCheckBox : UserControl
- {
- #region 事件
- ///// <summary>
- ///// 在鼠标捕获更改后发生
- ///// </summary>
- //[Description("在鼠标捕获更改后发生。")]
- //public new event EventHandler MouseCaptureChanged
- //{
- // add
- // {
- // this.checkedListBox.MouseCaptureChanged += value;
- // }
- // remove
- // {
- // this.checkedListBox.MouseCaptureChanged -= value;
- // }
- //}
- ///// <summary>
- ///// 指示某项的选中状态将要更改。直到事件发生后,该值才会更新
- ///// </summary>
- //[Description("指示某项的选中状态将要更改。直到事件发生后,该值才会更新。")]
- //public event ItemCheckEventHandler ItemCheck
- //{
- // add
- // {
- // this.checkedListBox.ItemCheck += value;
- // }
- // remove
- // {
- // this.checkedListBox.ItemCheck -= value;
- // }
- //}
- #endregion
- #region 成员变量
- // 显示的值
- private string _displayMember = string.Empty;
- // 实际的值
- private string _valueMember = string.Empty;
- #endregion
- #region 构造函数
- public C_StatusCheckBox()
- {
- InitializeComponent();
- }
- #endregion
- #region 属性
- /// <summary>
- /// 获取或者设定标签的内容
- /// </summary>
- [Description("获取或者设定标签的内容。")]
- public string Title
- {
- get
- {
- return this.lblTitle.Text;
- }
- set
- {
- this.lblTitle.Text = value;
- AdjustControl();
- }
- }
- /// <summary>
- /// 获取或者设定第一个复选框的文本内容
- /// </summary>
- [Description("获取或者设定第一个复选框的文本内容。")]
- public string TrueText
- {
- get
- {
- return this.chkTrue.Text;
- }
- set
- {
- this.chkTrue.Text = value;
- AdjustControl();
- }
- }
- /// <summary>
- /// 获取或者设定第二个复选框的文本内容
- /// </summary>
- [Description("获取或者设定第二个复选框的文本内容。")]
- public string FalseText
- {
- get
- {
- return this.chkFalse.Text;
- }
- set
- {
- this.chkFalse.Text = value;
- AdjustControl();
- }
- }
- /// <summary>
- /// 获取或者设定标签的对齐方式
- /// </summary>
- [Description("获取或者设定标签的对齐方式。")]
- [DefaultValue(System.Drawing.ContentAlignment.MiddleRight)]
- [Localizable(true)]
- public ContentAlignment TitleAlign
- {
- get
- {
- return this.lblTitle.TextAlign;
- }
- set
- {
- this.lblTitle.TextAlign = value;
- }
- }
- ///// <summary>
- ///// 获取或者设定控件是否可用
- ///// </summary>
- //public new bool Enabled
- //{
- // get
- // {
- // return this.checkedListBox.Enabled;
- // }
- // set
- // {
- // this.lblTitle.Enabled = value;
- // this.checkedListBox.Enabled = value;
- // this.TabStop = value;
- // }
- //}
- /// <summary>
- /// 获取或者设定选中的项目
- /// </summary>
- [Description("获取或者设定选中的项目。")]
- public Object[] SelectedValues
- {
- get
- {
- Object[] selectedValue = new Object[2];
- if (this.chkTrue.Checked && !this.chkFalse.Checked)
- {
- return new Object[] { 1 };
- }
- else if (!this.chkTrue.Checked && this.chkFalse.Checked)
- {
- return new Object[] { 0 };
- }
- else if (this.chkTrue.Checked && this.chkFalse.Checked)
- {
- return new Object[] { 1, 0 };
- }
- else
- {
- return new Object[] { };
- }
- }
- }
- /// <summary>
- /// 获取或者设定控件的字体
- /// </summary>
- public new Font Font
- {
- get
- {
- return base.Font;
- }
- set
- {
- base.Font = value;
- this.lblTitle.Font = value;
- this.chkTrue.Font = value;
- this.chkFalse.Font = value;
- }
- }
- #endregion
- #region 公开方法或者函数
- ///// <summary>
- ///// BeginUpdate
- ///// </summary>
- //public void BeginUpdate()
- //{
- // this.checkedListBox.BeginUpdate();
- //}
- ///// <summary>
- ///// EndUpdate
- ///// </summary>
- //public void EndUpdate()
- //{
- // this.checkedListBox.EndUpdate();
- //}
- ///// <summary>
- ///// 往项目列表中追加指定项目
- ///// </summary>
- ///// <param name="item">指定项目</param>
- //public void Add(CheckedBoxListItem item)
- //{
- // checkedListBox.Add(item);
- //}
- ///// <summary>
- ///// 移动指定的项目
- ///// </summary>
- ///// <param name="item">指定的项目</param>
- //public void Remove(CheckedBoxListItem item)
- //{
- // checkedListBox.Items.Remove(item);
- //}
- ///// <summary>
- ///// 移除所有的项目
- ///// </summary>
- //public void RemoveAll()
- //{
- // checkedListBox.Items.Clear();
- //}
- /// <summary>
- /// 清除所有项目的选中状态
- /// </summary>
- public void ClearItemCheck()
- {
- this.chkTrue.Checked = false;
- this.chkFalse.Checked = false;
- }
- /// <summary>
- /// 将所有项目选中状态
- /// </summary>
- public void AllItemCheck()
- {
- this.chkTrue.Checked = true;
- this.chkFalse.Checked = true;
- }
- ///// <summary>
- ///// 根据项目索引和标识设定项目的选中状态
- ///// </summary>
- ///// <param name="index">项目索引</param>
- ///// <param name="flg">选中与否标识</param>
- //public void SetSelected(int index, bool flg)
- //{
- // checkedListBox.SetSelected(index, flg);
- //}
- ///// <summary>
- ///// 根据项目的索引取得项目选中状态
- ///// </summary>
- ///// <param name="index">项目的索引</param>
- ///// <returns></returns>
- //public bool GetItemChecked(int index)
- //{
- // return checkedListBox.GetItemChecked(index);
- //}
- #endregion
- #region 受保护方法或者函数
- /// <summary>
- /// 自动计算并调整控件的位置
- /// </summary>
- protected void AdjustControl()
- {
- //if (LablePositionValue == LablePosition.Left)
- //{
- this.lblTitle.Location = new System.Drawing.Point(0, 0);
- this.chkTrue.Location = new System.Drawing.Point(this.lblTitle.Width +
- ControlsConst.CONTROLSPACE, 0);
- this.chkTrue.Size = new System.Drawing.Size(
- this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
- this.chkFalse.Location = new System.Drawing.Point(this.lblTitle.Width
- + this.chkTrue.Width + ControlsConst.CONTROLSPACE, 0);
- this.chkFalse.Size = new System.Drawing.Size(
- this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
- //this.checkedListBox.Location = new System.Drawing.Point(this.lblTitle.Width +
- // ControlsConst.CONTROLSPACE, 0);
- //this.checkedListBox.Size = new System.Drawing.Size(
- // this.Width - this.lblTitle.Width - ControlsConst.CONTROLSPACE, this.Height);
- //}
- //else if (LablePositionValue == LablePosition.Top)
- //{
- // this.lblTitle.Location = new System.Drawing.Point(0, 0);
- // this.checkedListBox.Location = new System.Drawing.Point(0, this.lblTitle.Height +
- // ControlsConst.CONTROLSPACE);
- // this.checkedListBox.Size = new System.Drawing.Size(this.Width,
- // this.Height - this.lblTitle.Height - ControlsConst.CONTROLSPACE);
- //}
- }
- #endregion
- #region 控件事件
- /// <summary>
- /// 控件的尺寸改变时发生的事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CheckedBoxListEx_SizeChanged(object sender, EventArgs e)
- {
- AdjustControl();
- }
- ///// <summary>
- ///// 离开控件时发生的事件
- ///// </summary>
- ///// <param name="sender"></param>
- ///// <param name="e"></param>
- //private void CheckedBoxListEx_Leave(object sender, EventArgs e)
- //{
- // this.checkedListBox.SelectedIndex = -1;
- //}
- #endregion
- }
- }
|