标签:
软件界面如上所示:点击接收窗体实现打开发送窗体,发送窗体点击“发送”,即可发送到接收窗体,可以实现窗体间的传值。
接收窗体的主要代码:
/// <summary> /// 打开发送窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOpen_Click(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.getValueDelegate = GetValue;//将方法赋给委托 f2.ShowDialog(); } /// <summary> /// 值传给窗体的文本框 /// </summary> /// <param name="str"></param> void GetValue(string str) { txtValue.Text = str; }
发送窗体的主要代码:
public delegate void GetValueDelegate(string str);//声明委托 public GetValueDelegate getValueDelegate;//定义委托 private void btnSend_Click(object sender, EventArgs e) { if(getValueDelegate!=null) { getValueDelegate(txtValue.Text); } }
不知道怎么上传代码,例子很简单,相信应该看得懂!
标签:
原文地址:http://www.cnblogs.com/sammo/p/5140342.html