form1: private void button1_Click(object sender, System.EventArgs e) { Form2 frm = new Form2(); frm.OnSendString += (text) => { textBox1.Text = text; }; frm.Show(); } form2: public delegate void SendStringHandler(String text); public event SendStringHandler OnSendString; private void button1_Click(object sender, EventArgs e) { if (OnSendString != null) { OnSendString("在WinForms程序里实现窗体传值的最佳实践"); } }
m_dlg.TextBoxChanged += new EventHandler( (sender1, e1) => { richTextBox1.Text = m_dlg.TextBoxValue; } ); =>相当于
m_dlg.TextBoxChanged += new EventHandler(m_dlg_textboxchanged); ... private void m_dlg_textboxchanged(object sender1, EventArgs e1) { richTextBox1.Text = m_dlg.TextBoxValue; }