Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _147_窗体传值
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2(ShowMsg);
form2.Show();
}
void ShowMsg(string str)
{
label1.Text = str;
}
}
}
From2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _147_窗体传值
{
//声明委托
public delegate void DelTest(string str);
public partial class Form2 : Form
{
//声明一个字段
private DelTest _del;
public Form2(DelTest del)
{
this._del = del;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_del(textBox1.Text);
}
}
}