This is what I have...
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);
}
}
This is what I wish would work...
private void plotMarker(PaintEventArgs e)
{
if(CheckBoxBoat0.Checked)
{
MessageBox.Show('Yehaaa');
}
}
Well what you can do is have a list of checkbox in your class
List<CheckBox> myCheckBoxList = new List<CheckBox>();
And when you create a checkbox you add it to the list
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);
}
}
And then you can access it by using the list
private void plotMarker(PaintEventArgs e)
{
if (myCheckBoxList[0].Checked)
{
MessageBox.Schow('Yehaaa');
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.