110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LINQTEST.CSDN.页面传值
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.str1 = this.textBox1.Text;
frm.str2 = this.textBox2.Text;
frm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.str1 = this.textBox3.Text;
frm.str2 = this.textBox4.Text;
frm.Show();
}
}
}
FORM2的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LINQTEST.CSDN.页面传值
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public string str1;
public string str2;
private void Form2_Load(object sender, EventArgs e)
{
this.textBox1.Text = str1;
this.textBox2.Text = str2;
}
}
}
你要的效果
public partial class Form7 : Form
{
public Form7()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form8 frm = new Form8();
frm.UpdateFormData += new EventHandler<EventInfo>(frm_UpdateFormData);
frm.ShowDialog();
}
void frm_UpdateFormData(object sender, EventInfo e)
{
this.textBox1.Text = e.str1;
this.textBox2.Text = e.str2;
}
}
namespace ApiDemo
{
public partial class Form8 : Form
{
public event EventHandler<EventInfo> UpdateFormData;
public Form8()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (UpdateFormData != null)
{
EventInfo et=new EventInfo();
et.str1=this.textBox1.Text;
et.str2=this.textBox2.Text;
UpdateFormData(null, et);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (UpdateFormData != null)
{
EventInfo et = new EventInfo();
et.str1 = this.textBox3.Text;
et.str2 = this.textBox4.Text;
UpdateFormData(null, et);
}
}
}
}
public class EventInfo : EventArgs
{
public string str1 { get; set; }
public string str2 { get; set; }
}