/*******************************************************************************
* 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
{
///
/// 扩展的复选框列表控件:可以多项选择
///
public partial class C_StatusCheckBox : UserControl
{
#region 事件
/////
///// 在鼠标捕获更改后发生
/////
//[Description("在鼠标捕获更改后发生。")]
//public new event EventHandler MouseCaptureChanged
//{
// add
// {
// this.checkedListBox.MouseCaptureChanged += value;
// }
// remove
// {
// this.checkedListBox.MouseCaptureChanged -= value;
// }
//}
/////
///// 指示某项的选中状态将要更改。直到事件发生后,该值才会更新
/////
//[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 属性
///
/// 获取或者设定标签的内容
///
[Description("获取或者设定标签的内容。")]
public string Title
{
get
{
return this.lblTitle.Text;
}
set
{
this.lblTitle.Text = value;
AdjustControl();
}
}
///
/// 获取或者设定第一个复选框的文本内容
///
[Description("获取或者设定第一个复选框的文本内容。")]
public string TrueText
{
get
{
return this.chkTrue.Text;
}
set
{
this.chkTrue.Text = value;
AdjustControl();
}
}
///
/// 获取或者设定第二个复选框的文本内容
///
[Description("获取或者设定第二个复选框的文本内容。")]
public string FalseText
{
get
{
return this.chkFalse.Text;
}
set
{
this.chkFalse.Text = value;
AdjustControl();
}
}
///
/// 获取或者设定标签的对齐方式
///
[Description("获取或者设定标签的对齐方式。")]
[DefaultValue(System.Drawing.ContentAlignment.MiddleRight)]
[Localizable(true)]
public ContentAlignment TitleAlign
{
get
{
return this.lblTitle.TextAlign;
}
set
{
this.lblTitle.TextAlign = value;
}
}
/////
///// 获取或者设定控件是否可用
/////
//public new bool Enabled
//{
// get
// {
// return this.checkedListBox.Enabled;
// }
// set
// {
// this.lblTitle.Enabled = value;
// this.checkedListBox.Enabled = value;
// this.TabStop = value;
// }
//}
///
/// 获取或者设定选中的项目
///
[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[] { };
}
}
}
///
/// 获取或者设定控件的字体
///
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 公开方法或者函数
/////
///// BeginUpdate
/////
//public void BeginUpdate()
//{
// this.checkedListBox.BeginUpdate();
//}
/////
///// EndUpdate
/////
//public void EndUpdate()
//{
// this.checkedListBox.EndUpdate();
//}
/////
///// 往项目列表中追加指定项目
/////
///// 指定项目
//public void Add(CheckedBoxListItem item)
//{
// checkedListBox.Add(item);
//}
/////
///// 移动指定的项目
/////
///// 指定的项目
//public void Remove(CheckedBoxListItem item)
//{
// checkedListBox.Items.Remove(item);
//}
/////
///// 移除所有的项目
/////
//public void RemoveAll()
//{
// checkedListBox.Items.Clear();
//}
///
/// 清除所有项目的选中状态
///
public void ClearItemCheck()
{
this.chkTrue.Checked = false;
this.chkFalse.Checked = false;
}
///
/// 将所有项目选中状态
///
public void AllItemCheck()
{
this.chkTrue.Checked = true;
this.chkFalse.Checked = true;
}
/////
///// 根据项目索引和标识设定项目的选中状态
/////
///// 项目索引
///// 选中与否标识
//public void SetSelected(int index, bool flg)
//{
// checkedListBox.SetSelected(index, flg);
//}
/////
///// 根据项目的索引取得项目选中状态
/////
///// 项目的索引
/////
//public bool GetItemChecked(int index)
//{
// return checkedListBox.GetItemChecked(index);
//}
#endregion
#region 受保护方法或者函数
///
/// 自动计算并调整控件的位置
///
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 控件事件
///
/// 控件的尺寸改变时发生的事件
///
///
///
private void CheckedBoxListEx_SizeChanged(object sender, EventArgs e)
{
AdjustControl();
}
/////
///// 离开控件时发生的事件
/////
/////
/////
//private void CheckedBoxListEx_Leave(object sender, EventArgs e)
//{
// this.checkedListBox.SelectedIndex = -1;
//}
#endregion
}
}