Solved

An easy one..

Posted on 2003-11-03
5
258 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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