winform 子窗体回传参数给父窗体

来源:互联网 发布:node sass windows 64 编辑:程序博客网 时间:2024/06/14 02:36

父窗体创建一个子窗体,当子窗体关闭时,想传递参数回复窗体时,需要用到的getDataHandler


1.父窗体创建子窗体:

Dialog dialog = new Dialog();                dialog.StartPosition = FormStartPosition.CenterParent;//居中                dialog.getDataHandler = Get_Dialog_Value;                dialog.ShowDialog();

2.父窗体的getDataHandler事件

public void Get_Dialog_Value(string str)        {            MessageBox.Show(str);          }

3.子窗体创建GetDataHandle

public delegate void GetDataHandler(string str);        public GetDataHandler getDataHandler;

4.子窗体调用getDataHandler回传

private void btnSure_Click(object sender, EventArgs e)        {getDataHandler("hello");}


0 0
原创粉丝点击