Delegate event 委托事件---两个From窗体使用委托事件

窗体如下:

Delegate event 委托事件---两个From窗体使用委托事件 Delegate event 委托事件---两个From窗体使用委托事件

 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

上一篇:AQS学习(一)自旋锁原理介绍(为什么AQS底层使用自旋锁队列?)


下一篇:java基础八 [序列化和文件的输入/输出](阅读Head First Java记录)