Accessing properties of Controls in another Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 forms (Form1 and Form2) in my C# project. I created the second form
from the main form like so:

Fom2 aForm = new Form2();
aForm.ShowDialog();

How do I access the properties of a control (label1) in Form1 from Form2?

Thanks
Andrew
 
I'd say you shouldn't directly manipulate controls on another form, but if
you need to - you could also do something like this:

from form2:

((Label)parent.Controls.Find("label1",true)[0]).Text = "Hello there";
 
Back
Top