using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Runtime;
using System.Windows.Forms;
using Dongke.WinForm.Utilities;
namespace Dongke.WinForm.Controls
{
///
/// 全选复选框列表控件
///
[ToolboxBitmap(typeof(CheckedListBox))]
[DefaultBindingProperty("SelectedValue"), DefaultProperty("Items"), DefaultEvent("ItemChecked")]
[LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue")]
//[Designer("System.Windows.Forms.Design.ListBoxDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public partial class CalCheckAllListBox : UserControl, IDKControl, IPopupControl, IDataVerifiable, IAsyncControl
{
#region 事件声明
#region HasErrorChanged
///
/// 当 HasError 属性的值更改时发生。
///
private static readonly object EventHasErrorChanged = new object();
///
/// 当 HasError 属性的值更改时发生。
///
[Description("当 HasError 属性的值更改时发生。"), Category("CustomerEx")]
public event EventHandler HasErrorChanged
{
add
{
base.Events.AddHandler(EventHasErrorChanged, value);
}
remove
{
base.Events.RemoveHandler(EventHasErrorChanged, value);
}
}
#endregion
#endregion
#region 成员变量
///
/// 是否全部选择
///
private bool? _isCheckAll = null;
///
/// 不确定选中时,选中的Item的Index
///
private List _indeterminateIndices = new List();
///
/// 焦点是否进入控件
///
private bool _entered = false;
///
/// 鼠标是否进入控件
///
private bool _mouseOver = false;
///
/// 边框颜色
///
private Color? _borderColor = null;
//private bool _isAllChecked = false;
#endregion
#region 构造函数
///
/// 扩展的复选框列表控件:可以全部选择
///
public CalCheckAllListBox()
{
this.InitializeComponent();
base.BackColor = SystemColors.Window;
base.BorderStyle = BorderStyle.FixedSingle;
this.chkAll.MouseWheel += chkAll_MouseWheel;
this.chkAll.GotFocus += chkAll_GotFocus;
}
#endregion
#region 实现
#region ListControl
#region 属性
///
/// 获取或设置控件的数据源
///
[Description("获取或设置控件的数据源。"), Category("ListControl")]
[AttributeProvider(typeof(IListSource))]
[DefaultValue(null)]
[RefreshProperties(RefreshProperties.Repaint)]
public object DataSource
{
get
{
return this.cklItem.DataSource;
}
set
{
this.cklItem.DataSource = value;
}
}
///
/// 获取或设置控件的显示的属性
///
[Description("获取或设置控件的显示的属性。"), Category("ListControl")]
//[DefaultValue(null)]
[DefaultValue("")]
[Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string DisplayMember
{
get
{
return this.cklItem.DisplayMember;
}
set
{
this.cklItem.DisplayMember = value;
}
}
///
/// 获取或设置提供自定义格式设置行为的 System.IFormatProvider。
///
[Description("获取或设置提供自定义格式设置行为的 System.IFormatProvider。"), Category("ListControl")]
[Browsable(false)]
[DefaultValue(null)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public IFormatProvider FormatInfo
{
get
{
return this.cklItem.FormatInfo;
}
set
{
this.cklItem.FormatInfo = value;
}
}
///
/// 获取或设置格式说明符字符,指示如何显示值。
///
[Description("获取或设置格式说明符字符,指示如何显示值。"), Category("ListControl")]
[DefaultValue("")]
[Editor("System.Windows.Forms.Design.FormatStringEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[MergableProperty(false)]
public string FormatString
{
get
{
return this.cklItem.FormatString;
}
set
{
this.cklItem.FormatString = value;
}
}
///
/// 获取或设置一个值,该值指示是否将格式设置应用于控件的 DisplayMember 属性。
///
[Description("获取或设置一个值,该值指示是否将格式设置应用于控件的 DisplayMember 属性。"), Category("ListControl")]
[DefaultValue(false)]
public bool FormattingEnabled
{
get
{
return this.cklItem.FormattingEnabled;
}
set
{
this.cklItem.FormattingEnabled = value;
}
}
///
/// 获取或设置由 DisplayMember 属性指定的成员属性的值。
///
[Description("获取或设置由 DisplayMember 属性指定的成员属性的值。"), Category("ListControl")]
[Bindable(true)]
[Browsable(false)]
[DefaultValue(null)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object SelectedValue
{
get
{
return this.cklItem.SelectedValue;
}
set
{
this.cklItem.SelectedValue = value;
}
}
///
/// 获取或设置一个属性,该属性将用作控件中的项的实际值。
///
[Description("获取或设置一个属性,该属性将用作控件中的项的实际值。"), Category("ListControl")]
//[DefaultValue(null)]
[DefaultValue("")]
[Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public string ValueMember
{
get
{
return this.cklItem.ValueMember;
}
set
{
this.cklItem.ValueMember = value;
}
}
#endregion
#region 事件声明
///
/// 当 DataSource 更改时发。
///
[Description("当 DataSource 更改时发。"), Category("ListControl")]
public event EventHandler DataSourceChanged
{
add
{
this.cklItem.DataSourceChanged += value;
}
remove
{
this.cklItem.DataSourceChanged -= value;
}
}
///
/// 当 DisplayMember 属性更改时发生。
///
[Description("当 DisplayMember 属性更改时发生。"), Category("ListControl")]
public event EventHandler DisplayMemberChanged
{
add
{
this.cklItem.DisplayMemberChanged += value;
}
remove
{
this.cklItem.DisplayMemberChanged -= value;
}
}
///
/// 在该控件绑定到数据值时发生。
///
[Description("在该控件绑定到数据值时发生。"), Category("ListControl")]
public event ListControlConvertEventHandler Format
{
add
{
this.cklItem.Format += value;
}
remove
{
this.cklItem.Format -= value;
}
}
///
/// 当 FormatInfo 属性的值更改时发生。
///
[Description("当 FormatInfo 属性的值更改时发生。"), Category("ListControl")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public event EventHandler FormatInfoChanged
{
add
{
this.cklItem.FormatInfoChanged += value;
}
remove
{
this.cklItem.FormatInfoChanged -= value;
}
}
///
/// 当 FormatString 属性的值更改时发生。
///
[Description("当 FormatString 属性的值更改时发生。"), Category("ListControl")]
public event EventHandler FormatStringChanged
{
add
{
this.cklItem.FormatStringChanged += value;
}
remove
{
this.cklItem.FormatStringChanged -= value;
}
}
///
/// 当 FormattingEnabled 属性的值更改时发生。
///
[Description("当 FormattingEnabled 属性的值更改时发生。"), Category("ListControl")]
public event EventHandler FormattingEnabledChanged
{
add
{
this.cklItem.FormattingEnabledChanged += value;
}
remove
{
this.cklItem.FormattingEnabledChanged -= value;
}
}
///
/// 当 SelectedValue 属性更改时发生。
///
[Description("当 SelectedValue 属性更改时发生。"), Category("ListControl")]
public event EventHandler SelectedValueChanged
{
add
{
this.cklItem.SelectedValueChanged += value;
}
remove
{
this.cklItem.SelectedValueChanged -= value;
}
}
///
/// 当 ValueMember 属性更改时发生。
///
[Description("当 ValueMember 属性更改时发生。"), Category("ListControl")]
public event EventHandler ValueMemberChanged
{
add
{
this.cklItem.ValueMemberChanged += value;
}
remove
{
this.cklItem.ValueMemberChanged -= value;
}
}
#endregion
#region 公共方法
///
/// 返回指定项的文本表示形式。
///
/// 从中获取要显示的内容的对象
///
/// 如果未指定 DisplayMember 属性,则由 GetItemText(System.Object)
/// 返回的值是此项的 ToString 方法的值。否则,该方法返回在 DisplayMember
/// 属性中指定的成员的字符串值,该成员被指定给在 item 参数中指定的对象。
///
public string GetItemText(object item)
{
return this.cklItem.GetItemText(item);
}
#endregion
#endregion
#region ListBox
#region 属性
///
/// 获取或设置多列显示中列的宽度。
///
[Description("获取或设置多列显示中列的宽度。"), Category("ListBox")]
[DefaultValue(0)]
[Localizable(true)]
public int ColumnWidth
{
get
{
return this.cklItem.ColumnWidth;
}
set
{
this.cklItem.ColumnWidth = value;
}
}
///
/// 获取控件中的项之间的制表符的宽度。
///
[Description("获取控件中的项之间的制表符的宽度。"), Category("ListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ListBox.IntegerCollection CustomTabOffsets
{
get
{
return this.cklItem.CustomTabOffsets;
}
}
///
/// 获取或设置控件的水平滚动条可滚动的宽度。
///
[Description("获取或设置控件的水平滚动条可滚动的宽度。"), Category("ListBox")]
[DefaultValue(0)]
[Localizable(true)]
public int HorizontalExtent
{
get
{
return this.cklItem.HorizontalExtent;
}
set
{
this.cklItem.HorizontalExtent = value;
}
}
///
/// 获取或设置一个值,该值指示是否在控件中显示水平滚动条。
///
[Description("获取或设置一个值,该值指示是否在控件中显示水平滚动条。"), Category("ListBox")]
[DefaultValue(false)]
[Localizable(true)]
public bool HorizontalScrollbar
{
get
{
return this.cklItem.HorizontalScrollbar;
}
set
{
this.cklItem.HorizontalScrollbar = value;
}
}
///
/// 获取或设置一个值,该值指示控件是否应调整大小以避免只显示项的局部。
///
[Description("获取或设置一个值,该值指示控件是否应调整大小以避免只显示项的局部。"), Category("ListBox")]
[DefaultValue(true)]
[Localizable(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public bool IntegralHeight
{
get
{
return this.cklItem.IntegralHeight;
}
set
{
this.cklItem.IntegralHeight = value;
}
}
///
/// 获取或设置一个值,该值指示控件是否支持多列。
///
[Description("获取或设置一个值,该值指示控件是否支持多列。"), Category("ListBox")]
[DefaultValue(false)]
public bool MultiColumn
{
get
{
return this.cklItem.MultiColumn;
}
set
{
this.cklItem.MultiColumn = value;
}
}
///
/// 获取控件中所有项的组合高度。
///
[Description("获取控件中所有项的组合高度。"), Category("ListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public int PreferredHeight
{
get
{
return this.cklItem.PreferredHeight;
}
}
///
/// 获取或设置一个值,该值指示是否任何时候都显示垂直滚动条。
///
[Description("获取或设置一个值,该值指示是否任何时候都显示垂直滚动条。"), Category("ListBox")]
[DefaultValue(false)]
[Localizable(true)]
public bool ScrollAlwaysVisible
{
get
{
return this.cklItem.ScrollAlwaysVisible;
}
set
{
this.cklItem.ScrollAlwaysVisible = value;
}
}
///
/// 获取或设置控件中当前选定项的从零开始的索引。
///
[Description("获取或设置控件中当前选定项的从零开始的索引。"), Category("ListBox")]
[Bindable(true)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual int SelectedIndex
{
get
{
return this.cklItem.SelectedIndex;
}
set
{
this.cklItem.SelectedIndex = value;
}
}
///
/// 获取一个集合,该集合包含控件中所有当前选定项的从零开始的索引。
///
[Description("获取一个集合,该集合包含控件中所有当前选定项的从零开始的索引。"), Category("ListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ListBox.SelectedIndexCollection SelectedIndices
{
get
{
return this.cklItem.SelectedIndices;
}
}
///
/// 获取或设置控件中的当前选定项。
///
[Description("获取或设置控件中的当前选定项。"), Category("ListBox")]
[Bindable(true)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object SelectedItem
{
get
{
return this.cklItem.SelectedItem;
}
set
{
this.cklItem.SelectedItem = value;
}
}
///
/// 获取包含控件中当前选定项的集合。
///
[Description("获取包含控件中当前选定项的集合。"), Category("ListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ListBox.SelectedObjectCollection SelectedItems
{
get
{
return this.cklItem.SelectedItems;
}
}
///
/// 获取或设置在控件中选择项所用的方法。
///
[Description("获取或设置在控件中选择项所用的方法。"), Category("ListBox")]
[DefaultValue(typeof(SelectionMode), "One")]
public virtual SelectionMode SelectionMode
{
get
{
return this.cklItem.SelectionMode;
}
set
{
this.cklItem.SelectionMode = value;
}
}
///
/// 获取或设置一个值,该值指示控件中的项是否按字母顺序排序。
///
[Description("获取或设置一个值,该值指示控件中的项是否按字母顺序排序。"), Category("ListBox")]
[DefaultValue(false)]
public bool Sorted
{
get
{
return this.cklItem.Sorted;
}
set
{
this.cklItem.Sorted = value;
}
}
///
/// 获取或搜索控件中当前选定项的文本。
///
[Description("获取或搜索控件中当前选定项的文本。"), Category("ListBox")]
[Bindable(false)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public virtual string ItemText
{
get
{
return this.cklItem.Text;
}
set
{
this.cklItem.Text = value;
}
}
///
/// 获取或设置控件中第一个可见项的索引。
///
[Description("获取或设置控件中第一个可见项的索引。"), Category("ListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int TopIndex
{
get
{
return this.cklItem.TopIndex;
}
set
{
this.cklItem.TopIndex = value;
}
}
///
/// 获取或设置一个值,它指示控件在通过使用 CustomTabOffsets 整数数组绘制字符串时是否识别并展开制表符。
///
[Description("获取或设置一个值,它指示控件在通过使用 CustomTabOffsets 整数数组绘制字符串时是否识别并展开制表符。"), Category("ListBox")]
[Browsable(false)]
[DefaultValue(false)]
public bool UseCustomTabOffsets
{
get
{
return this.cklItem.UseCustomTabOffsets;
}
set
{
this.cklItem.UseCustomTabOffsets = value;
}
}
///
/// 获取或设置一个值,该值指示控件在绘制其字符串时是否可识别和展开制表符。
///
[Description("获取或设置一个值,该值指示控件在绘制其字符串时是否可识别和展开制表符。"), Category("ListBox")]
[DefaultValue(true)]
public bool UseTabStops
{
get
{
return this.cklItem.UseTabStops;
}
set
{
this.cklItem.UseTabStops = value;
}
}
#region Never
/*
[Description(""), Category("CustomerEx")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
public Padding ItemPadding
{
get
{
return base.Padding;
}
set
{
}
}
*/
/*
///
/// 获取或设置控件的绘图模式。
///
[Description("获取或设置控件的绘图模式。"), Category("CustomerEx")]
//[Browsable(false)]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
//[EditorBrowsable(EditorBrowsableState.Never)]
[RefreshProperties(RefreshProperties.Repaint)]
[DefaultValue(typeof(DrawMode), "Normal")]
public virtual DrawMode DrawMode
{
get
{
return this.clstItem.DrawMode;
}
set
{
this.clstItem.DrawMode = value;
}
}
///
/// 获取或设置控件中项的高度。
///
[Description("获取或设置控件中项的高度。"), Category("CustomerEx")]
//[Browsable(false)]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//[DefaultValue(13)]
[DefaultValue(16)]
[Localizable(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public virtual int ItemHeight
{
get
{
return this.clstItem.ItemHeight;
}
set
{
this.clstItem.ItemHeight = value;
//this.pnlItem.Height = this.clstItem.ItemHeight + 2;
}
}
///
/// 获取控件的项
///
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Description("获取控件的项。"), Category("CustomerEx")]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Localizable(true)]
[MergableProperty(false)]
//public ListBox.ObjectCollection Items
public ListBox.ObjectCollection ListBoxItems
{
get
{
return this.clstItem.Items;
}
}
*/
#endregion
#endregion
#region 事件声明
///
/// 在单击 Item 控件时发生。
///
[Description("在单击 Item 控件时发生。"), Category("ListBox")]
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
public event EventHandler ItemClick
{
add
{
this.cklItem.Click += value;
}
remove
{
this.cklItem.Click -= value;
}
}
///
/// 在所有者绘制的 Item 在视觉外观更改时发生。
///
[Description("在所有者绘制的 Item 在视觉外观更改时发生。"), Category("ListBox")]
public event DrawItemEventHandler DrawItem
{
add
{
this.cklItem.DrawItem += value;
}
remove
{
this.cklItem.DrawItem -= value;
}
}
///
/// 当用户使用鼠标指针单击 Item 控件时发生。
///
[Description("当用户使用鼠标指针单击 Item 控件时发生。"), Category("ListBox")]
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
public event MouseEventHandler ItemMouseClick
{
add
{
this.cklItem.MouseClick += value;
}
remove
{
this.cklItem.MouseClick -= value;
}
}
///
/// 在 SelectedIndex 属性或 SelectedIndices集合更改后发生。
///
[Description("在 SelectedIndex 属性或 SelectedIndices集合更改后发生。"), Category("ListBox")]
public event EventHandler SelectedIndexChanged
{
add
{
this.cklItem.SelectedIndexChanged += value;
}
remove
{
this.cklItem.SelectedIndexChanged -= value;
}
}
///
/// 当 Text 属性更改时发生。
///
[Description("当 Text 属性更改时发生。"), Category("ListBox")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public event EventHandler ItemTextChanged
{
add
{
this.cklItem.TextChanged += value;
}
remove
{
this.cklItem.TextChanged -= value;
}
}
#region Never
/*
///
/// 当 Padding 属性的值更改时发生。
///
[Description("当 Padding 属性的值更改时发生。"), Category("CustomerEx")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler ItemPaddingChanged
{
add
{
this.clstItem.PaddingChanged += value;
}
remove
{
this.clstItem.PaddingChanged -= value;
}
}
///
/// 在绘制 Item 控件时发生。
///
[Description("在绘制 Item 控件时发生。"), Category("CustomerEx")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public event PaintEventHandler ItemPaint
{
add
{
this.clstItem.Paint += value;
}
remove
{
this.clstItem.Paint -= value;
}
}
*/
/*
///
/// 创建所有者描述的控件和确定列表项的大小时发生。
///
//[Browsable(false)]
//[EditorBrowsable(EditorBrowsableState.Never)]
[Description("创建所有者描述的控件和确定列表项的大小时发生。"), Category("CustomerEx")]
public event MeasureItemEventHandler MeasureItem
{
add
{
this.clstItem.MeasureItem += value;
}
remove
{
this.clstItem.MeasureItem -= value;
}
}
*/
#endregion
#endregion
#region 公共方法
///
/// 当向控件中一次添加一个项时,通过防止该控件绘图来维护性能,直到调用 EndUpdate() 方法为止。
///
public void BeginUpdate()
{
this.cklItem.BeginUpdate();
}
///
/// 取消选择控件中的所有项。
///
public void ClearSelected()
{
this.cklItem.ClearSelected();
}
///
/// 在 BeginUpdate() 方法挂起绘制后,该方法恢复绘制控件。
///
public void EndUpdate()
{
this.cklItem.EndUpdate();
}
///
/// 查找 Item 中以指定字符串开始的第一个项。
///
/// 要搜索的文本
/// 找到的第一个项的从零开始的索引;如果找不到匹配项,则返回 ListBox.NoMatches。
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public int FindString(string s)
{
return this.cklItem.FindString(s);
}
///
/// 查找 Item 中以指定字符串开头的第一个项。搜索从特定的起始索引处开始。
///
/// 要搜索的文本
/// 项的从零开始的索引,该项在要搜索的第一个项之前。设置为负一 (-1) 以从控件的开始处进行搜索。
/// 找到的第一个项的从零开始的索引;如果找不到匹配项,则返回 ListBox.NoMatches。
public int FindString(string s, int startIndex)
{
return this.cklItem.FindString(s, startIndex);
}
///
/// 查找 Item 中第一个精确匹配指定字符串的项。
///
/// 要搜索的文本
/// 找到的第一个项的从零开始的索引;如果找不到匹配项,则返回 ListBox.NoMatches。
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public int FindStringExact(string s)
{
return this.cklItem.FindStringExact(s);
}
///
/// 查找 Item 中第一个精确匹配指定字符串的项。搜索从特定的起始索引处开始。
///
/// 要搜索的文本
/// 项的从零开始的索引,该项在要搜索的第一个项之前。设置为负一 (-1) 以从控件的开始处进行搜索。
/// 找到的第一个项的从零开始的索引;如果找不到匹配项,则返回 ListBox.NoMatches。
public int FindStringExact(string s, int startIndex)
{
return this.cklItem.FindStringExact(s, startIndex);
}
///
/// 返回 Item 中某项的高度。
///
/// 要返回其高度的项的从零开始的索引
/// 指定的项的高度,以像素为单位
public int GetItemHeight(int index)
{
return this.cklItem.GetItemHeight(index);
}
///
/// 返回控件中的项的边框。
///
/// 要返回其边框的项的从零开始的索引
/// 表示指定项的边框
public Rectangle GetItemRectangle(int index)
{
return this.cklItem.GetItemRectangle(index);
}
///
/// 返回一个值,该值指示是否选定了指定的项
///
/// 项的从零开始的索引,根据该索引确定该项是否被选定
/// 如果当前在控件中选定了指定的项,则为 true;否则为 false。
public bool GetSelected(int index)
{
return this.cklItem.GetSelected(index);
}
///
/// 返回指定坐标处的项的从零开始的索引
///
/// System.Drawing.Point 对象,包含用于获取项索引的坐标
/// 在指定坐标处找到的项的从零开始的索引;如果找不到匹配项,则返回 ListBox.NoMatches。
public int IndexFromPoint(Point p)
{
return this.cklItem.IndexFromPoint(p);
}
///
/// 返回指定坐标处的项的从零开始的索引。
///
/// 要搜索的位置的 x 坐标
/// 要搜索的位置的 y 坐标
/// 在指定坐标处找到的项的从零开始的索引;如果找不到匹配项,则返回 ListBox.NoMatches。
public int IndexFromPoint(int x, int y)
{
return this.cklItem.IndexFromPoint(x, y);
}
///
/// 强制控件使其工作区无效并立即重绘自己和任何子控件。
///
public virtual void ItemRefresh()
{
this.cklItem.Refresh();
}
///
///
///
public virtual void ItemResetBackColor()
{
this.cklItem.ResetBackColor();
}
///
///
///
public virtual void ItemResetForeColor()
{
this.cklItem.ResetForeColor();
}
///
/// 选择或清除对 Item 中指定项的选定。
///
/// Item中要选择或清除对其选定的项的从零开始的索引
/// 如果为 true,则选择指定的项;否则为 false
public void SetSelected(int index, bool value)
{
this.cklItem.SetSelected(index, value);
}
///
/// 返回控件的字符串表示形式。
///
/// 一个字符串,它描述控件类型、控件中的项计数,如果该计数不为 0,则还描述控件中第一项的 Text 属性
public new string ToString()
{
return this.cklItem.ToString();
}
#endregion
#endregion
#region CheckedListBox
#region 属性
///
/// 该控件中选中索引的集合。
///
[Description("该控件中选中索引的集合。"), Category("CheckedListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public CheckedListBox.CheckedIndexCollection CheckedIndices
{
get
{
return this.cklItem.CheckedIndices;
}
}
///
/// 该控件中选中项的集合。
///
[Description("该控件中选中项的集合。"), Category("CheckedListBox")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public CheckedListBox.CheckedItemCollection CheckedItems
{
get
{
return this.cklItem.CheckedItems;
}
}
///
/// 获取或设置一个值,该值指示当选定项时是否应切换复选框。
///
[Description("获取或设置一个值,该值指示当选定项时是否应切换复选框。"), Category("CheckedListBox")]
[DefaultValue(true)]
public bool CheckOnClick
{
get
{
return this.cklItem.CheckOnClick;
}
set
{
this.cklItem.CheckOnClick = value;
}
}
///
/// 获取该控件中项的集合。
///
[Description("获取该控件中项的集合。"), Category("CheckedListBox")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Localizable(true)]
[MergableProperty(false)]
public CheckedListBox.ObjectCollection Items
{
get
{
return this.cklItem.Items;
}
}
///
/// 获取或设置一个值,该值指示复选框是否有 Flat 或 Normal 的 System.Windows.Forms.ButtonState。
///
[Description("获取或设置一个值,该值指示复选框是否有 Flat 或 Normal 的 System.Windows.Forms.ButtonState。"), Category("CheckedListBox")]
[DefaultValue(false)]
public bool ThreeDCheckBoxes
{
get
{
return this.cklItem.ThreeDCheckBoxes;
}
set
{
this.cklItem.ThreeDCheckBoxes = value;
}
}
///
/// 获取或设置一个值,该值确定是使用 System.Drawing.Graphics 类 (GDI+) 还是 System.Windows.Forms.TextRenderer 类 (GDI) 呈现文本。
///
[Description("获取或设置一个值,该值确定是使用 System.Drawing.Graphics 类 (GDI+) 还是 System.Windows.Forms.TextRenderer 类 (GDI) 呈现文本。"), Category("CheckedListBox")]
[DefaultValue(false)]
public bool UseCompatibleTextRendering
{
get
{
return this.cklItem.UseCompatibleTextRendering;
}
set
{
this.cklItem.UseCompatibleTextRendering = value;
this.chkAll.UseCompatibleTextRendering = value;
}
}
/*
//
// 摘要:
// 获取一个值,该值表示 System.Windows.Forms.CheckedListBox 的绘制元素的模式。此属性与该类无关。
//
// 返回结果:
// 通常为 Normal 的 System.Windows.Forms.DrawMode。
//[Browsable(false)]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//public override DrawMode DrawMode
//{
// get;
// set;
//}
//
// 摘要:
// 获取项区域的高度。
//
// 返回结果:
// 项区域的高度(以像素为单位)。
//[Browsable(false)]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//public override int ItemHeight
//{
// get;
// set;
//}
*/
#endregion
#region 事件声明
///
/// 当某项的选中状态更改时发生。
///
[Description("当某项的选中状态更改时发生。"), Category("CheckedListBox")]
public event ItemCheckEventHandler ItemCheck
{
add
{
this.cklItem.ItemCheck += value;
}
remove
{
this.cklItem.ItemCheck -= value;
}
}
/*
/////
///// 当用户单击 Item 控件时发生。
/////
//[Description("当用户单击 Item 控件时发生。"), Category("CustomerEx")]
//[Browsable(true)]
//[EditorBrowsable(EditorBrowsableState.Always)]
//public event EventHandler ItemClick
//{
// add
// {
// this.clstItem.Click += value;
// }
// remove
// {
// this.clstItem.Click -= value;
// }
//}
/////
///// 当用户使用鼠标单击 Item 控件时发生。
/////
//[Description("当用户使用鼠标单击 Item 控件时发生。"), Category("CustomerEx")]
//[Browsable(true)]
//[EditorBrowsable(EditorBrowsableState.Always)]
//public event MouseEventHandler ItemMouseClick
//{
// add
// {
// this.clstItem.MouseClick += value;
// }
// remove
// {
// this.clstItem.MouseClick -= value;
// }
//}
*/
/*
//
// 摘要:
// 在所有者描述的 System.Windows.Forms.CheckedListBox 的可视方位更改时发生。此事件与此类无关。
//[Browsable(false)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//public event DrawItemEventHandler DrawItem;
//
// 摘要:
// 创建所有者描述的 System.Windows.Forms.ListBox 和确定列表项的大小时发生。此事件与此类无关。
//[Browsable(false)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//public event MeasureItemEventHandler MeasureItem;
*/
#endregion
#region 公共方法
///
/// 返回指示指定项是否选中的值。
///
/// 项的索引
/// 如果选中该项,则为 true;否则为 false。
public bool GetItemChecked(int index)
{
return this.cklItem.GetItemChecked(index);
}
///
/// 返回指示当前项的复选状态的值。
///
/// 要获取其选中值的项的索引
/// System.Windows.Forms.CheckState 值之一。
public CheckState GetItemCheckState(int index)
{
return this.cklItem.GetItemCheckState(index);
}
///
/// 将指定索引处的项的 System.Windows.Forms.CheckState 设置为 Checked。
///
/// 要为其设置复选状态的项的索引
/// 若要将该项设置为选中,则为 true;否则为 false
public void SetItemChecked(int index, bool value)
{
this.cklItem.SetItemChecked(index, value);
}
///
/// 设置指定索引处项的复选状态。
///
/// 要为其设置状态的项的索引
/// System.Windows.Forms.CheckState 值之一
public void SetItemCheckState(int index, CheckState value)
{
this.cklItem.SetItemCheckState(index, value);
}
#endregion
#endregion
#region CklCheckedListBox
#region 属性
///
/// 获取选中的文本
///
[Description("获取选中的文本。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public string[] CheckedTexts
{
get
{
return this.cklItem.CheckedTexts;
}
}
///
/// 获取选中的值
///
[Description("获取选中的值。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public object[] CheckedValues
{
get
{
return this.cklItem.CheckedValues;
}
}
///
/// 获取选中项的文本表示形式,用【,】隔开。
///
[Description("获取选中项的文本表示形式,用【,】隔开。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public string CheckedText
{
get
{
return this.cklItem.CheckedText;
}
}
///
/// 获取选中项的值,用【,】隔开
///
[Description("获取选中项的值,用【,】隔开。"), Category("CklCheckedListBox")]
[DefaultValue(null)]
public string CheckedValue
{
get
{
return this.cklItem.CheckedValue;
}
}
/////
///// 获取或设置控件是否单项选中。
/////
//[Description("获取或设置控件是否单项选中。"), Category("CustomerEx")]
//[DefaultValue(false)]
////[Browsable(false)]
//[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//public bool SimpleChecked
//{
// get
// {
// return this.cklItem.SimpleChecked;
// }
// set
// {
// this.cklItem.SimpleChecked = value;
// }
//}
///
/// 获取一个值,该值指示控件是否有输入焦点。
///
[DefaultValue(false)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public virtual bool Entered
{
get
{
return this._entered;
}
protected set
{
if (this._entered != value)
{
this._entered = value;
this.InvalidateBorder();
}
}
}
///
/// 获取一个值,该值指示鼠标是否在控件上方。
///
[DefaultValue(false)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public virtual bool MouseOver
{
get
{
return this._mouseOver;
}
protected set
{
if (this._mouseOver != value)
{
this._mouseOver = value;
this.InvalidateBorder();
}
}
}
#endregion
#region 事件处理
///
/// 当某项的选中状态更改后发生。
///
[Description("当某项的选中状态更改后发生。"), Category("CklCheckedListBox")]
public event ItemCheckedEventHandler ItemChecked
{
add
{
this.cklItem.ItemChecked += value;
}
remove
{
this.cklItem.ItemChecked -= value;
}
}
#endregion
#region 公有方法
///
/// 返回指定项的成员属性的值
///
/// 项
/// 值
public virtual object GetItemValue(object item)
{
return this.cklItem.GetItemValue(item);
}
///
/// 返回选中项的文本表示形式
///
/// 选中项的文本
public virtual List GetCheckedItemTexts()
{
return this.cklItem.GetCheckedItemTexts();
}
///
/// 返回选中项的成员属性的值
///
/// 选中项的值
public virtual List