Solved

An easy one..

Posted on 2003-11-03
5
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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