c# winForm父子窗口 通过委托进行信息传递

转载于https://zhidao.baidu.com/question/360469626552901972.html paperkey的回答

public class Form1
{
private void button_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.GetValue+= new EventHandler(SendValue);
f.ShowDialog();
}
//操作form2传来的值
private void SendValue(object sender, EventArgs e)
{
string form2Str = sender as string;
//form2Str就是传过来的值
}
}
public class Form2
{
public event EventHandler GetValue;
//窗口关闭事件
private void form_Closed(object sender, EventArgs e) //参数类型不记得了,自己点出来
{
if (GetValue!= null)
{
string s = txtBox1.Text;//假如这个就是要传的值
GetValue(s, e);
}
}
}
原文地址:https://www.cnblogs.com/xuezhu/p/12935884.html