窗体1:
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 委托窗体传值
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Form2 f2 = new Form2(GetTextValue);
f2.Show();
}
private void GetTextValue( string s)
{
this.textBox1.Text = s;
}
}
}
窗体2:
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 委托窗体传值
{
public delegate void DelTO(string s);
public partial class Form2 : Form
{
private DelTO del;
public Form2(DelTO del)
{
this.del = del;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
del(this.textBox1.Text);
}
}
}