How to change control property from flowlayoutpanel?

How do I change the property of a control in the flowlayout panel, assuming you add controls programmatically and think that the name of each control is the same?

For example, this image shows you that there are 2 text fields and two buttons, how would I change the back color of button 2? Assuming controls were added at runtime.

alt text

foreach(Controls ctrl in flowlayoutpanel1.Controls)
{
//What should I put here?
}
+3
source share
2 answers

, - . , ( i18n). . "button2" "button2" , :

foreach (Control ctl in flp.Controls) {
    if ("button2".Equals(ctl.Tag)) {
        ctl.BackColor = Color.Red;
    }

}

, , . , , - "button2" , , , , .

ETA: , Name.

, sender .

+3

Control.ControlCollection.Find.

flowLayoutPanel1.Controls.Add(new Button() { Text = "button 1", Name = "btn1" });
Button btn1 = flowLayoutPanel1.Controls.Find("btn1", true).FirstOrDefault() as Button;
btn1.Text = "found!";
+3

Source: https://habr.com/ru/post/1768554/


All Articles