110,534
社区成员
发帖
与我相关
我的任务
分享
private void button4_Click(object sender, EventArgs e)
{
for (int i = 0; i < 33; i++)
{
CheckBox chk = new CheckBox();
if (i == 31) chk.Text = "全选";
else if (i == 32) chk.Text = "不选";
else chk.Text = (i + 1).ToString().PadLeft(2, '0');
chk.Location = new Point(i % 12 * 50, i / 12 * 30);
chk.Width = 50;
chk.Name = "checkBox" + i;
chk.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
this.Controls.Add(chk);
}
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
switch ((sender as CheckBox).Text)
{
case "全选": // 可以实现全选和不选的功能 不选那一个CheckBox可以去掉
{
for (int i = 0; i < 31; i++)
{
(this.Controls["checkBox" + i] as CheckBox).Checked = (sender as CheckBox).Checked;
}
break;
}
default: break; // 其它情况在本行处理
}
}
this.checkedListBox1.ColumnWidth = 40;
this.checkedListBox1.MultiColumn = true;
for (int i = 0; i < 100; i++)
{
this.checkedListBox1.Items.Add(i.ToString().PadLeft(2));
}
for (int i = 0; i < 30; i++)
{
CheckBox cb = new CheckBox();
cb.Text = i.ToString().PadLeft(2);
cb.Name = "myCheckBox" + i.ToString().PadLeft(2);
cb.Left = ...; //这里调整位置
cb.Top = ...;
this.Controls.Add(cb);
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 33; i++)
{
CheckBox chk = new CheckBox();
if (i == 31) chk.Text = "全选";
else if (i == 32) chk.Text = "不选";
else chk.Text = (i+1).ToString().PadLeft(2, '0');
chk.Location = new Point(i % 12 * 50, i / 12 * 30);
chk.Width = 50;
chk.Name = "checkBox" + i;
this.Controls.Add(chk);
}
}
private void button1_Click(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is CheckBox)
{
(c as CheckBox).Checked = true;//全不选只要为false
}
}
}