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

如何获取子窗口数据
现在有两窗口Form1和Form2,现在我想请问下,如何在Form1中获取Form2中的TextBox中的值?

------解决方案--------------------
窗体间传值
------解决方案--------------------
属性。。。。
------解决方案--------------------
http://topic.csdn.net/u/20110407/19/c1068d69-7331-4d02-bc0b-f5ba7a5f8dd8.html
------解决方案--------------------
给你个简单的
form2里面这样写:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
 public string Txt
{
get
{

this.textBox1.Text = "这是form2的代码";
return this.textBox1.Text;
}
}
}

form1里面这样就可以了
 public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show( GetFormTextBoxValle(new Form2()));
}

private string GetFormTextBoxValle(Form2 frm)
{
if(frm!=null)

return frm.Txt;
}
return string.Empty;
}
}
------解决方案--------------------
用类的构造方法实现传值
------解决方案--------------------
属性就行,如果不知道神马是属性,就得查查了