窗体如下:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 f = new Form2(); f.ShowDialog(); } private void Form1_Load(object sender, EventArgs e) { Form2.SendMessageEvent += Form2_SendMessageEvent; } void Form2_SendMessageEvent() { this.textBox1.Text = this.textBox1.Text +"收消息成功"; } } public partial class Form2 : Form { public delegate void SendMessageDelegate(); public static event SendMessageDelegate SendMessageEvent; public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SendMessageEvent(); } }
demo下载路径:https://download.csdn.net/download/u010713920/10302679
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!