C#中窗体2如何调用窗体1的数据
刚好没事帮你做了一个实例,
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;
}
}
被调用的窗体1类 对象名=new 被调用的窗体1类();
对象名.Show();
from2 fr = new from2(a);
fr.show();
窗体2中:
public string a;
public qgMain()
{
InitializeComponent();
}
public qgMain(string str):this()
{
this.a = str;
}
或者:
窗体1中:
from2 fr = new from2();
fr.show();
fr.a = a;
窗体2中:
public string a;