2 回答

TA貢獻(xiàn)1833條經(jīng)驗 獲得超4個贊
double total = 0;
try
{
foreach (GroupBox ctrl in this.Controls.OfType<GroupBox>()) //We get all of groupboxes that is in our form (We want the checkboxes which are only in a groupbox.Not all of the checkboxes in the form.)
{
foreach (CheckBox c in ctrl.Controls.OfType<CheckBox>()) //We get all of checkboxes which are in a groupbox.One by one.
{
if (c.Checked == true)
{
total += Convert.ToDouble(c.Tag);
}
}
}
tbComplementPrice.Text = string.Format("{0:F2}", total);
}
catch
{
MessageBox.Show("Error calculating the complement price", "Error", MessageBoxButtons.OK);
}

TA貢獻(xiàn)1946條經(jīng)驗 獲得超4個贊
我認(rèn)為這會奏效
foreach(CheckBox c in groupBox1.Controls.OfType<CheckBox>())
{
c.Checked = true;
}
- 2 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報