C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...









How to get a Control from another Form


Posted Date: 19 Jul 2008    Resource Type: Code Snippets    Category: Winforms Controls

Posted By: saji       Member Level: Gold
Rating:     Points: 5



The code sample addresses the following scenario:

You have a two forms - form1 and form2. "form2" is invoked from "form1". After invoking "form2", you want to change some of form2 controls' properties of from form1.

Solution to this problem is given in this example:

For implementing this we need to do two things

1) Make sure that controls( need access from form1) in form2 are public.
2) Declare form2 globally in form1


In this example we have 2 forms:

1) Form1: Contains 2 button one invoking form2 and another for changing form2.TextBox.Value
2) Form2: Contains a public TextBox (Note: this must be declared as public , u can set it by changing “Modifier” property of textbox to “public” )



public partial class Form1 : Form
{
//Declare form2 globally
Form2 seond;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
seond = new Form2();
seond.Show();

}

private void button2_Click(object sender, EventArgs e)
{
seond.textBox1.Text = "Hiii...from form1";
}
}





Attachments

  • Code (19640-19424-Code.rar)



  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Change textbox's vaule from another form  .  Change Textbox's value  .  Access controls across Forms  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Get selected values from CheckedListBox
    Previous Resource: Cute ActiveX Control
    Return to Discussion Resource Index
    Post New Resource
    Category: Winforms Controls


    Post resources and earn money!
     
    Related Resources



    dotNet Slackers   BizTalk Adaptors    Web Design

    fax server

    Contact Us    Privacy Policy    Terms Of Use