Code Snippet
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Form2Text =
"Before";
// assign variables to Form2 before calling ShowDialog
// ShowDialog will return control after Form2 is closed
if (frm.ShowDialog() == DialogResult.OK)
// you still can access object frm
// it is closed but not disposed
label1.Text = frm.Form2Text;
else
label1.Text =
"operation canceled";
// when you leave the method object frm will go out of scope
// and will be disposed by Garbage Collector
// If want to access frm from other methods
// or keep it alive, you have to define a class variable for it
}
}