如何将GroupBox中的所有文字和文字颜色标签设置为自定义或默认值?

问题描述 投票:0回答:1

如何将 GroupBox 中的 Labels 的 Text 和 ForeColor 重置为自定义或默认值?

enter image description here

c# winforms label groupbox
1个回答
0
投票

最简单的方法是创建一个函数,查看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);
        }

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.