Is using iteration and the OpenForms property to modify a control from another form a bad practice?

For example, I have Form1 and Form2. This is from the click event in a button on Form1:

Form2 form2 = (Form2)Application.OpenForms["Form2"]; foreach (Label label in form2.Controls) { if (label.Name == "labelName") { label.Text = textbox1.Text; } } 

I found that with this you can modify the controls from another form without changing their access modifiers.

submitted by /u/G40-ovoneL
[link] [comments]

Leave a Reply