1:先看测试的效果图:
2:全部的代码
1 using System; 2 using System.Windows.Forms; 3 4 namespace WindowsForms 5 { 6 public partial class ParentForm : Form 7 { 8 public void ParentGetvalue(string text) 9 { 10 this.textBox1.Text = text; 11 labelp.Text ="获取的值是:"+ text; 12 } 13 public Action<string> doinvokeP; 14 private void ParentForm_Load(object sender, EventArgs e) 15 { 16 ChildForm cf = new ChildForm(this); 17 doinvokeP += cf.ChildGetValue; cf.Show(); 18 } 19 private void btnParent_Click(object sender, EventArgs e) 20 { 21 if (doinvokeP != null) 22 { 23 doinvokeP.Invoke(textBox1.Text); 24 } 25 } 26 27 public ParentForm() 28 { 29 InitializeComponent(); 30 } 31 } 32 }