How to access control properties from another Form

  • Thread starter Thread starter Andrew Diabo
  • Start date Start date
A

Andrew Diabo

I have 2 forms in my C# project (Form1 and Form2). I called Form2
from Form1 using the following:

Form2 newform = new Form2();
Form2.ShowDialog();

How do I change properties of a control (label1) in Form1 from Form2?
Is this possible?

Thanks in advance.

Andrew
 
It might be best, IMO, to create an event within Form2 that is fired when
something interesting happens. Then Form1 can subscribe to this event on
"newform" before calling ShowDialog(). Now you can let Form1 decide, inside
an event handler, how information is to be displayed within any Form1 child
controls.
 
Hi Tim,

Thanks for taking the time to respond. How does Form1 subscribe to an
event created in Form2?

Thanks again in advance.

Andrew
 
Hi Tim,

Thank you so much for the sample project. It helped a lot.

Thanks again.

Andrew
 
Back
Top