最简单的方法是创建一个函数,查看groupbox中的每个控件并设置它的值。注意,你可以修改组框中的任何控件。
private void ResetLabelText(Control control)
{
List<Label> lbls = groupBox1.Controls.OfType<Label>().ToList();
foreach (var lbl in lbls)
{
lbl.Text = "...";
lbl.ForeColor = default(Color);
}
}
然后可以像这样通过点击按钮来调用该函数。
private void button4_Click_1(object sender, EventArgs e)
{
ResetLabelText(groupBox1);
}