这就是我的......
private void blablabla()
{
for (int i=1; i<count+1; i++)
{
int item_number = panelBoats.Controls.Count;
CheckBox chb = new CheckBox();
chb.Name = "CheckBoxBoat" + i.ToString();
chb.Text = "Boat " + i.ToString();
chb.Location = new Point(10, item_number * 15);
panelBoats.Controls.Add(chb);
}
}
这是我希望的工作......
private void plotMarker(PaintEventArgs e)
{
if(CheckBoxBoat0.Checked)
{
MessageBox.Show('Yehaaa');
}
}
答案 0 :(得分:0)
你可以做的是在你的班级中有一个复选框列表
List<CheckBox> myCheckBoxList = new List<CheckBox>();
当您创建一个复选框时,将其添加到列表
private void blablabla()
{
for (int i = 1; i < count + 1; i++)
{
int item_number = panelBoats.Controls.Count;
CheckBox chb = new CheckBox();
chb.Name = "CheckBoxBoat" + i.ToString();
chb.Text = "Boat " + i.ToString();
chb.Location = new Point(10, item_number * 15);
panelBoats.Controls.Add(chb);
//Add the checkBox to the list
myCheckBoxList.add(chb);
}
}
然后您可以使用列表
访问它private void plotMarker(PaintEventArgs e)
{
if (myCheckBoxList[0].Checked)
{
MessageBox.Schow('Yehaaa');
}
}