Solved

An easy one..

Posted on 2003-11-03
5
226 Views
Last Modified: 2010-04-16
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?
0
Comment
Question by:jooon
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9670553
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
 

Author Comment

by:jooon
ID: 9670640
For example change value/properties on a textBox from Form1 on Form2.

Like in Delphi:
Form2.Edit1.BackColor := clRed;
0
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
ID: 9670694
In your properties in the Development system, click on the control and change the 'Modifiers' to public or internal
0
 
LVL 4

Expert Comment

by:wile_e_coyote
ID: 9670761
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
 

Author Comment

by:jooon
ID: 9670772
Thank you! Thank you both! ;)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now