发布网友 发布时间:2023-08-02 15:17
共4个回答
热心网友 时间:2024-08-24 04:49
刚好没事帮你做了一个实例,
Form1中的数据传到Form3,
然后form3的数据再传回到form1
form1.cs代码
private void btn_select_Click(object sender, EventArgs e)
{
Form3 fm3 = new Form3(this.textBox1.Text.Trim());
fm3.returntxt += new Form3.ReturnTxt(fm3_returntxt);
fm3.ShowDialog();
}
private void fm3_returntxt(string str, object form)
{
//throw new Exception("The method or operation is not implemented.");
this.textBox1.Text = str;
((Form3)form).Close();
}
form3.cs代码
public partial class Form3 : Form
{
private string str = "";
public delegate void ReturnTxt(string str, object form);
public event ReturnTxt returntxt;
public Form3()
{
InitializeComponent();
}
public Form3(string a)
{
InitializeComponent();
str = a;
}
private void button1_Click(object sender, EventArgs e)
{
if (returntxt != null)
returntxt(this.textBox2.Text.Trim(), this);
}
private void Form3_Load(object sender, EventArgs e)
{
this.textBox1.Text = str;
}
}
热心网友 时间:2024-08-24 04:50
在窗体的一个控件方法里面写上:热心网友 时间:2024-08-24 04:50
窗体1中:热心网友 时间:2024-08-24 04:51
打开窗体2的时候传个参数 this