How do get the content(Text or Numbers) of a text box in a windows form and take it to the next windows form and use it there.

Recommended Answers

All 5 Replies

pass the textbox as a parameter which will be used in form2

Form1

form2 form2 = new form2(textBox1.Text)
form2.Show();

Then make a new constructor for the other form, with string parameter and assign this parameter to your textbox (form2).

Form2

Form2(string parameter)
{
textBox1.Text = parameter;
}

Thanx a lot AngelicOne

Sorry but form2 is incorrect. Put the new constructor where initializecomponent is..

Form2(string parameter)
{
InitializeComponent();
textBox1.Text = parameter;
}

something similar how to send back information to the calling form

if you want to pass information back and forth the easiest way is to pass a reference to the parent form into the child form. See my tutorial.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.