An easy one..

Hi, I couldn't find the answer with google so I turn to you. I'm new in C#.

How can I access a control in Form2 from Form1?
jooonAsked:
Who is Participating?
 
psdavisCommented:
In your properties in the Development system, click on the control and change the 'Modifiers' to public or internal
0
 
Arthur_WoodCommented:
in general, this is NOT a good design, as you are LINKING the design of Form1 to the design of Form2, and if you decide to change Form2 later, and forget to make the corresponding change in Form1, your application will break.

Can you give a specific example of what you are trying to do?

AW
0
 
jooonAuthor Commented:
For example change value/properties on a textBox from Form1 on Form2.

Like in Delphi:
Form2.Edit1.BackColor := clRed;
0
 
wile_e_coyoteCommented:
Like psdavis said, first you have to click on the control in Form2 and change the Modifiers property to "public".  Then you can reference the control from Form1 as follows:

Form2 f2 = new Form2 ();   //creates an instance of form2
f2.MyControl.Enabled = false;  
f2.Show ();                  //makes form2 visible
0
 
jooonAuthor Commented:
Thank you! Thank you both! ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.