Reputation: 123
How do you reset the Text and ForeColor of Labels in a GroupBox to a custom or default value?
Upvotes: 0
Views: 342
Reputation: 123
The easiest way is to create a function that looks at each control in the groupbox and set it's value. Notice, you can modify any control in the 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);
}
}
The function can then be called from a button click like so.
private void button4_Click_1(object sender, EventArgs e)
{
ResetLabelText(groupBox1);
}
Upvotes: 0