二、CheckBox 控件 1.功能 CheckBox 控件指定某个特定条件是处于打开状态还是处于关闭状态,它常用于为用户提供“是/否”或“真/假”选项。 2.属性 CheckBox 控件常用属性及说明如表所示。 if (this.checkBox1.Checked == False && this.checkBox2.Checked ==False && checkBox3.Checked == False) { MessageBox.Show("至少选一项爱好"); return; } if (radioButton1.Checked == False && radioButton2.Checked == False) { MessageBox.Show("请选择性别"); return; } 八、Listbox 和 CheckedListbox 显示一个 ListBox,其中在每项的左边显示一个复选框。 命名空间: System.Windows.Forms public partial class Form3 : Form { public Form3() //将文本框中的内容添加到listbox中 { InitializeComponent(); textBox1.Text = "请输入添加的项目"; } private void button1_Click(object sender, EventArgs e) { listBox1.Items.Add(textBox1.Text); textBox1.Text = ""; } private void button2_Click(object sender, EventArgs e) { listBox1.Items.Remove(listBox1.Text); } private void button3_Click(object sender, EventArgs e) { listBox1.Items.Clear(); } } // Moves the checked items from the CheckedListBox to the listBox. private void button2_Click(object sender, System.EventArgs e) { listBox1.Items.Clear(); button3.Enabled=false ; for (int i=0; i< checkedListBox1.CheckedItems.Count;i++) { listBox1.Items.Add(checkedListBox1.CheckedItems[i]); } if (listBox1.Items.Count>0) button3.Enabled=true; } checklistbox方法: CheckedListBox.GetItemChecked 方法返回指示指定项是否选中的值。 参数 index :项的索引。 返回值:如果选中该项,则为 true;否则为 false。 异常类型 条件 ArgumentException 指定的 index 小于零。 - 或 - 指定的 index 大于或等于列表中项的计数。 CheckedListBox.GetItemCheckState 方法返回指示当前项的复选状态的值。 参数 index :要获取其选中值的项的索引。 返回值:CheckState 值之一(checked或unchecked)。 private void WhatIsChecked_Click(object sender, System.EventArgs e) { // Display in a...