Here's what I have so far:
[code]
private void frmServerChecker_Load(object sender, EventArgs e)
{
txtDomain.Focus(); //Text box for user to input a domain name
/* Add Check Boxes Dynamically
// Opted not to go this route for now
for (int count = 0; count < 4; count++)
{
int y = 45;
CheckBox[] cb= new CheckBox[count];
for (int i=0; i
cb[i] = new CheckBox();
cb[i].Location = new Point(30, y);
grpDiag.Controls.Add(cb[i]);
y += 15;
}
//this.Controls.Add(cb[count]);
}
*/
// Add checkboxes created in Design View to group box Control Collection
grpOptions.Controls.Add(chkHTTP);
grpOptions.Controls.Add(chkFTP);
grpOptions.Controls.Add(chkPOP);
grpOptions.Controls.Add(chkSMTP);
// Add labels created in Design View to group box Control Collection
grpDiag.Controls.Add(lblHTTPStatus);
grpDiag.Controls.Add(lblFTPStatus);
grpDiag.Controls.Add(lblPOPStatus);
grpDiag.Controls.Add(lblSMTPStatus);
}
private void cmdRunDiagnostics_Click(object sender, EventArgs e)
{
foreach (Control box in grpDiag.Controls)
{
int httpIndex = grpDiag.Controls.GetChildIndex(chkHTTP);
}
}
[/code]
The command button code will get me the Index of the first checkbox, but I can't figure out how to check for the checkbox properties to see whether the box is checked. In VB 6, this was easy because of the Index field we could set during design time, but I can't find out how to make this something I can iterate through in a for loop (which I'll need to do).
Ideally, I'd like to be able to do something like this:
[code]
for (int x=0; x<4; x++)
{
bool status[x] = checkbox[x].checked;
if (status[x] == 1)
{
label[x].Text = "Checkbox is checked";
}
}
[/code]
Or something like that. Please forgive any syntax issues in this example as I did it on the fly.
VulpesPosted Aug 1, 2012, 11:41 AM
Don SartainPosted Aug 1, 2012, 11:59 AM
private void cmdRunDiagnostics_Click(object sender, EventArgs e)
{
int chkHttpIndex = grpOptions.Controls.GetChildIndex(chkHTTP);
int lblHttpIndex = grpDiag.Controls.GetChildIndex(lblHTTPStatus);
for (int count = chkHttpIndex; count < chkHttpIndex + 4; count++)
{
CheckBox cb = (CheckBox)grpOptions.Controls[count];
if (cb.Checked)
{
int index = lblHttpIndex + count - chkHttpIndex;
Label lbl = (Label)grpDiag.Controls[index];
lbl.Text = "Checkbox is Checked";
}
else
{
int index = lblHttpIndex + count - chkHttpIndex;
Label lbl = (Label)grpDiag.Controls[index];
lbl.Text = "Checkbox is Not Checked";
}
}