- Create a public property on
Form2
to take the data - Set the property before the
Show()
method
e.g.
public class Form2 : Window
{
public Foo TramsferredInformation {get; set;}
}
public class Form1 : Window
{
private void button1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.TramsferredInformation = Whatever;
f.Show();
}
}
Foo
is the type of data you want to transfer, string or some complext type etc.
Off topic, its is a bad idea to have identifiers like
Form1
,
Form2
and the variable name "
f
". I assume this is just for ease of use in the question, but if not use meaningful names or you'll not be able to keep track if the project size increases or other people need to look at your code.