Demo窗体图片,Form1
Demo窗体图片,Form2
公共委托
using System;
namespace _DeleFrm
{
public class Dele
{
public static Action<string> SendDele;
}
}
form1窗体代码
using System;
using System.Windows.Forms;
namespace _DeleFrm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Dele.SendDele = Receive;//委托
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}
/// <summary>
/// 接收数据方法
/// </summary>
/// <param name="Msg"></param>
private void Receive(string Msg)
{
textBox1.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ")+Msg+"\r\n");
}
}
}
form2窗体代码
using System;
using System.Windows.Forms;
namespace _DeleFrm
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Send(textBox1.Text);
}
/// <summary>
/// 信息发送
/// </summary>
/// <param name="a"></param>
private void Send(string a)
{
Dele.SendDele(a);
}
}
}