How return data for a Showdialog()

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
 
K

Keith Patrick

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;

}
}
 
P

Patrick Steele

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")
...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top