The best way is for Form2 to signal an event which Form1 handles and gets the new data via a public property in form2. That way, Form2 need no nothing about Form1, and Form1 need only get teh data if it is actually interested in it.
In the child form:
public partial class frmChild : Form
{
public event EventHandler Changed;
protected virtual void OnChanged(EventArgs e)
{
EventHandler eh = Changed;
if (eh != null)
{
eh(this, e);
}
}
private void DoSomethingToChangeData()
{
OnChanged(null);
}
}
----- The asign to eh is in case the handler changes between null check
----- and exec.
----- (unlikely, but possible)
----- The null check is to ensure there is a handler. If not, better to
----- ignore it gracefully, than to rely on the thrown exception
----- (NullReferenceException)
In the Parent form:
public frmParent()
{
frmChild.Change += new frmChange.ChangeHandler(Changed);
}
private void ShowChildForm()
{
frmChild fd = new frmChild();
fd.ShowDialog();
}
private void Changed(object sender, EventArgs e)
{
Form2 f = sender as Form2;
if (f != null)
{
myLabel.Text = f.Data;
}
}