This can be solved in several ways, a simple approach is using static variables, see:
How to Pass Data One Form to Another in Windows Form Application[
^]
Some other options are discussed here:
Passing Data Between Forms[
^]
Or you could do it like this:
public partial class FormMain : Form
{
FormSub form2;
public FormMain()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
form2 = new FormSub();
form2.TextBoxValue = "First Value";
form2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
form2.TextBoxValue = "Changed Value";
}
}
public partial class FormSub : Form
{
public FormSub()
{
InitializeComponent();
}
public string TextBoxValue
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
}