子窗体:
public partial class ChildForm : Form
{public ChildForm()
{
InitializeComponent();
}
//声明一个委托
public delegate void DisplayUpdateDelegate(string str);
//声明事件
public event DisplayUpdateDelegate ShowUpdate;
private void button1_Click(object sender, EventArgs e)
{
if (ShowUpdate != null)
{
ShowUpdate(textBox1.Text.ToString());
}
}
}
主窗体:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void ShowMessage(string str)
{
textBox1.Text = str;}
private void ShowChilid_Click(object sender, EventArgs e)
{
ChildForm frm = new ChildForm();
frm.ShowUpdate += new ChildForm.DisplayUpdateDelegate(ShowMessage);
frm.Show();
}
}