Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,i have two forms,in form1 i have a texbox,how can i access textbox in form2?
Posted
Updated 28-Jul-11 15:13pm
v2

 
Share this answer
 
If you are writing a Windows Forms App, one way to do it is to create a property for the textbox on your Form2, like this.
C#
public string TextBoxValue
{
   get
   {
      return TextBox1.Text;
   }
   set
   {
      TextBox1.Text = value;
   }
}

And then, you can set values on your Form1, like this.
C#
Form2 f2 = new Form2();
f2.TextBoxValue = "YourValue";
f2.Show();
 
Share this answer
 
Comments
Christian Graus 28-Jul-11 20:41pm    
Of course, the fact you create the form and then show it right away, makes this example less useful and basically worse than the correct answer ( to use delegates )
walterhevedeich 28-Jul-11 20:45pm    
Oh, you're right. Must have misunderstood the question.

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