Winfrom子窗体关闭时如何为主窗体的TextBox赋值
子窗体中有个按钮,一个TextBox1,点击按钮时获取TextBox的值,然后子窗体关闭,主窗体里TextBox显示TextBox1的值
------解决方案--------------------http://www.cnblogs.com/cosoft/archive/2011/08/08/2130659.html
------解决方案--------------------主窗体:
按钮事件:
Form2 frm = new Form2();
if (frm.ShowDialog() == DialogResult.OK)
{
textBox1.Text = frm.TextValue;
}
子窗体:
属性: public string TextValue
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
点击按钮事件:
TextValue = textBox1.Text;
this.DialogResult = DialogResult.OK;
------解决方案--------------------在子画面里
public string value = "";
//点击时把子画面TEXTBOX里的值付给变量value
private void button1_Click(object sender, EventArgs e)
{
value = this.textBox1.Text;
}
private void Form2_Load(object sender, EventArgs e)
{
this.textBox1.Text = "123";