ShowDialog 的子窗体回传数据到父窗体

以前做B/S ,现在改C/S 方法不是很一样
Form1 里面
加入 set 访问器 
string str_temp1;
public string str_test
{
set
{
str_temp1=value;
}
}
弹出Form2窗体
 private void button1_Click(object sender, System.EventArgs e)
  {
   Form2 frm2=new Form2();
   frm2.Owner = this;
      frm2.ShowDialog();
   this.textBox1.Text=str_temp1;
  }
Form2 窗体里面
private void button1_Click(object sender, System.EventArgs e)
  {
   if(this.textBox1.Text != "")
   {
    Form1 pfrm = (Form1)this.Owner;
    pfrm.str_test = this.textBox1.Text;
    this.Close();
   }
   else
   {
    MessageBox.Show("请输入!");
   }
  }

没有办法,好长时间没有接触WinForm了,以前只是用Delphi 作过一些WinForm 的程序
posted @ 2005-07-29 11:41  jhtchina  阅读(1952)  评论(2)    收藏  举报