Above is a Google Search link on how to pass variables in the Form's constructor...
Alternatively, if this approach is not suitable, ie: values need to be passed after initialization, then the following example will do the trick:
Second Form (receiver):
using System.Windows.Forms;
namespace WFPassVariablesBetweenForms
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void SetValue(string text)
{
textBox1.Text = text;
}
}
}
Main Form (Sender):
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace WFPassVariablesBetweenForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var xxx = new Form2();
xxx.Show();
}
private void button1_Click(object sender, EventArgs e)
{
var xxx = Application.OpenForms.Cast<Form>().Where(x => x.Name == "Form2").FirstOrDefault();
((Form2)xxx).SetValue(textBox1.Text);
}
}
}
The danger with this solution isthat it is tightly bound. Can be refactored for loose dependency but that is not the purpose of this example.