先创建2个窗体
建立窗体Form1
建立窗体Form2
编写代码
使用委托,事件,完成窗体传值。
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public delegate void MyDelegate(string value);
public event MyDelegate MyDelegateEvent;
private void button1_Click(object sender, EventArgs e)
{
MyDelegateEvent(this.textBox1.Text);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnShowForm2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.MyDelegateEvent += Form2_MyDelegateEvent;
form2.Show();
}
private void Form2_MyDelegateEvent(string value)
{
this.txtname.Text = value;
}
}
|