Solved

An easy one..

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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