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); } } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步