I need to have like 5 or more checkboxes that are in an array so they can be accesed by index (checkbox[3]) and that they are seen on the windows form?
How do I make a set of checkboxes using C#?
The code below will create an array of three elements of CheckBox controls and position them on a form starting at the top/left of the form. You will probably want to make the array a private variable of the form so that it exists throughout the form's lifetime. You can then access each element of the array using an index to get to each checkbox.
CheckBox[] cb = new CheckBox[2];
int i;
for (int i = 0; i %26lt;= cb.Length - 1; i++) {
cb(i) = new CheckBox();
cb(i).Visible = true;
cb(i).Parent = this;
if ((i == 0)) {
cb(0).Top = 0;
} else {
cb(i).Top = cb(i - 1).Top + cb(i).Height;
}
cb(i).Text = "CheckBox " + i.ToString();
}
Reply:CheckBox[] cb = new CheckBox[2]; int i;
for (i = 0; i %26lt;= cb.Length - 1; i++){
cb[i] = new CheckBox();
cb[i].Visible = true;
cb[i].Parent = this;
if ((i == 0)) {
cb[0].Top = 0;
}
else {
cb[i].Top = cb[i - 1].Top + cb[i].Height;
}
cb[i].Text = "CheckBox " + i.ToString();
} Report It
Reply:I typed "freehand" so the bugs weren't caught as I typed. It's obvious to me that "i" was declared twice (outside the for loop and inside) and that the indexer brackets were parentheses instead of square brackets as they should have been. One of the hazards of using both C# and VB.NET. Report It
Reply:me no comprende, can u ask me in spanglish?
lady palm
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment