How return data for a Showdialog()

  • Thread starter Thread starter Freddy Coal
  • Start date Start date
F

Freddy Coal

Hi, I make a a program with two Form, I call Form2 as showdialog()

I Would like receive data when Form2 is closed, how make that?. How return
data when the form is closing or closed?.

Thanks in advance.

Freddy Coal
 
public class Form2 : Form {
private Object _DataSource;
public Object DataSource {...}
}

public class Form1 : Form {
public void HandleShowForm2Click(Object sender, EventArgs e) {
Form2 form = new Form2();
if (form.ShowDialog() == DialogResult.Cancel) {
return;
}

Object yourResult = form.DataSource;

}
}
 
Hi, I make a a program with two Form, I call Form2 as showdialog()

I Would like receive data when Form2 is closed, how make that?. How return
data when the form is closing or closed?.

The form may be closed (i.e. not visible), but the object still remains
in memory. Just create some public properties on Form2 with your return
information and you can access them in the calling form:

Form2 form = new Form2();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ReturnData = "itworks")
...
}
 
Back
Top