如题所述
public Form1()
{
InitializeComponent();
CheckBox check;
for (int i = 0; i < 10; i++)
{
check = new CheckBox();
check.Text = i.ToString();
check.Location = new Point(0, i * 25);
check.CheckedChanged += new EventHandler(check_CheckedChanged);
this.Controls.Add(check);
}
}
List<string> checkBoxTextList = new List<string>();
void check_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkbox = sender as CheckBox;
if (checkbox.Checked)
{
if (!checkBoxTextList.Contains(checkbox.Text))
{
checkBoxTextList.Add(checkbox.Text);
}
}
else
{
if (checkBoxTextList.Contains(checkbox.Text))
{
checkBoxTextList.Remove(checkbox.Text);
}
}
}
{
InitializeComponent();
CheckBox check;
for (int i = 0; i < 10; i++)
{
check = new CheckBox();
check.Text = i.ToString();
check.Location = new Point(0, i * 25);
check.CheckedChanged += new EventHandler(check_CheckedChanged);
this.Controls.Add(check);
}
}
List<string> checkBoxTextList = new List<string>();
void check_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkbox = sender as CheckBox;
if (checkbox.Checked)
{
if (!checkBoxTextList.Contains(checkbox.Text))
{
checkBoxTextList.Add(checkbox.Text);
}
}
else
{
if (checkBoxTextList.Contains(checkbox.Text))
{
checkBoxTextList.Remove(checkbox.Text);
}
}
}
温馨提示:答案为网友推荐,仅供参考