CheckBox cb;
ArrayList ary = new ArrayList();
for (int i = 0 ; i < 5 ; i ++)
{
cb = new CheckBox();
ary.Add(cb);
}private void button1_Click(object sender , System.EventArgs e)
{
//你首先得遍历找出你有哪几个checkBox控件,然后将其checkBox.Text加listBox中去
//我不知道你怎么建立这个数组的??
for(int i = 0 ; i < ary.Count; i++)
{
CheckBox c = (CheckBox) ary[i];
if(c.Checked)
{
listbox.items.add(c.Text);
}
}
}
ArrayList ary = new ArrayList();
for (int i = 0 ; i < 5 ; i ++)
{
cb = new CheckBox();
ary.Add(cb);
}private void button1_Click(object sender , System.EventArgs e)
{
//你首先得遍历找出你有哪几个checkBox控件,然后将其checkBox.Text加listBox中去
//我不知道你怎么建立这个数组的??
for(int i = 0 ; i < ary.Count; i++)
{
CheckBox c = (CheckBox) ary[i];
if(c.Checked)
{
listbox.items.add(c.Text);
}
}
}
for(int j = 0; j < tc.TabPages[i].Controls.Count ; j ++)
{
GroupBox gb = new GroupBox();
if(object.ReferenceEquals(tc.TabPages[i].Controls[j].GetType(),gb.GetType()))
{
for(int h = 0; h < tc.TabPages[i].Controls[j].Controls.Count ; h ++)
{
RadioButton rb = new RadioButton();
if(object.ReferenceEquals(tc.TabPages[i].Controls[j].Controls[h].GetType(),rb.GetType()))
{
rb = (RadioButton)tc.TabPages[i].Controls[j].Controls[h];
rb.Checked = false;
}
}
}
}
cbArr = new CheckBox[n];然后按钮事件:foreach(CheckBox cb in cbArr)
{
if(cb.Checked)
{
listbox.items.add(c.Text);
}
}
public class myCheckBox :CheckBox
{
private Button bt;
private ListBox lb;
//constructor
public myCheckBox(Button bt1,ListBox lb1)
{
this.bt = bt1;
this.lb = lb1;
this.bt.Click += new System.EventHandler(this.AddTextToListBox);
}
private void AddTextToListBox()
{
if(this.Checked)
{this.lb.Items.Add(this.Text);}
}
}//note : you must create ListBox ,Button object first
//,then create CheckBox(s) objectButton button1 = new Button();
button1.Click += new System.EventHandler(button1_Click);
ListBox lb = new ListBox();//note : you shold crete myCheckBox type object ,not CheckBox
for(int i = 0 ;i<100;i++
{
myCheckBox cb = new myCheckBox(button1,lb);
}
///----------end (not test the code , i think you can debug it)