Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hello everybody,

Im trying to get a value of a textbox from Form 1 and when Form 2 loads the textbox of Form2 should show that value. Im using c#.

Anyone can help pls?
Posted

Thanks ecerybody,all of your posts where useful,but the way i used was just simple.i just made the textbox public,and then on Form1 ,in the button click event that loads form2 i set the textbox value.its worked ;)
 
Share this answer
 
 
Share this answer
 
In Form1.cs:
C#
private Form2 otherForm;
private void GetOtherFormTextBox()
{
    textBox1.Text = otherForm.TextBox1.Text;
}

In Form2.cs:

C#
public TextBox TextBox1
{
    get
    {
        return textBox1;
    }
}
 
Share this answer
 
A number of approaches to pass a value from one form to another form are discussed at
How to Pass Control Values between Windows Forms
[^]. You can choose one that suits you best and go ahead and implement it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900