日期:2014-05-18  浏览次数:21353 次

C#两个窗口之间相互调用
我想通过Form1来调用Form2中textbox的值,但是Form1中不存在textbox,大家帮一下!

------解决方案--------------------
把Form2的TextBox设为public,
在Form1中 Form2 frm = new Form2();
string s = frm.TextBox1.Text;
------解决方案--------------------
你调用的又不是textbox 你调用的是textbox的值,所以Form1中存不存在没有关系
------解决方案--------------------
将Form2中textbox的modifiers 属性设置成Public
然后在form1中 
 Form2 FM2 = new Form2();
 string str = FM2.textBox1.Text;
------解决方案--------------------
form1
Private void button1_click(....)
{
From2 f2=new Form2();
f2.myevent+=give;
f2.show();
}
public void give(string name)
{
this.label1.Text=name;
}

Form2
public delegate void mydel(string name);
public event mydel myevent;

Private void button1_click(....)
{
if(myevent!=null)
{
myevent(this.TextBox1.Text);
}
}