private void checkedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
if(e.NewValue==CheckState.Checked)
{
//Item被选中……
}
else
{
//Item没被选中……
}
}
{
if(e.NewValue==CheckState.Checked)
{
//Item被选中……
}
else
{
//Item没被选中……
}
}
textBox1.Text = checkedListBox1.Items[e.Index].ToString();
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication16
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.CheckedListBox checkedListBox1;
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// checkedListBox1
//
this.checkedListBox1.CheckOnClick = true;
this.checkedListBox1.Items.AddRange(new object[] {
"11111111111",
"22222222222",
"33333333333",
"44444444444",
"55555555555"});
this.checkedListBox1.Location = new System.Drawing.Point(0, 16);
this.checkedListBox1.Name = "checkedListBox1";
this.checkedListBox1.Size = new System.Drawing.Size(152, 132);
this.checkedListBox1.TabIndex = 0;
this.checkedListBox1.ThreeDCheckBoxes = true;
this.checkedListBox1.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.checkedListBox1_ItemCheck);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(256, 64);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(544, 333);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1,
this.checkedListBox1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void checkedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
if(e.CurrentValue==CheckState.Unchecked)
{
this.textBox1.Text=this.checkedListBox1.SelectedItem.ToString();
}
else
{
this.textBox1.Text="";
}
}
}
}