How to access control properties from another Form

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
 
T

Tim Wilson

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.
 
A

Andrew Diabo

Hi Tim,

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

Thanks again in advance.

Andrew
 
A

Andrew Diabo

Hi Tim,

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

Thanks again.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top